/* GCC */

#include <cstdio>
#include <iostream>

using namespace std;

const int nMax = 1016;

int A[nMax][nMax];
int n, m, n1, m1, k;
long long ans = 0;

void add (int i, int j)
{
    int a = k - A[i][j];
    ans += a;

    for (int i1 = i; i1 < i+n1; i1++)
        for (int j1 = j; j1 < j+m1; j1++)
            A[i1][j1] += a, A[i1][j1] %= k;
}

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

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

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            scanf ("%d", &A[i][j]);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if ( A[i][j] != 0 )
            {
                if ((j + m1 <= m) && (i + n1 <= n))
                    add (i, j);
                else
                {
                    printf ("impossible\n", i, j);
                    return 0;
                }
            }

    cout << ans << endl;

    return 0;
}
