/* GCC */

#include <stdio.h>
#define max 1000

int n, m, n1, m1, k, cur, i, j, sums[max][max];

inline int getSum(int row, int column)
{
    if (row < 0 || column < 0)
        return 0;
    return sums[row][column];
}

int main()
{
    freopen("display.in", "r", stdin);
    freopen("display.out", "w", stdout);

    scanf("%d %d %d %d %d", &n, &m, &n1, &m1, &k);

    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
        {
            scanf("%d", &cur);
            sums[i][j] = getSum(i - 1, j) + getSum(i, j - 1) - getSum(i - 1, j - 1);
            cur = (cur + sums[i][j] - getSum(i - n1, j) - getSum(i, j - m1) + getSum(i - n1, j - m1)) % k;
            if (cur != 0)
            {
                if (i + n1 <= n && j + m1 <= m)
                    sums[i][j] += k - cur;
                else
                {
                    printf("impossible\n");
                    return 0;
                }
            }
        }

    printf("%d\n", sums[n - 1][m - 1]);
    return 0;
}
