/* GCC */

#define maxn 1000
#define maxm 1000

#include <stdio.h>

int a[maxn][maxm];
bool ver = true;
int n, m, n1, m1;

using namespace std;

inline void step(int x, int y, int k, int& opcount)
{
    if (y > m - m1 || x > n - n1)
    {
        if (a[x][y] != 0)
            ver = false;
        return;
    }
    if (a[x][y] != 0)
    {
        int ops = k - a[x][y];
        for (int i = 0; i < n1; i++)
            for (int j = 0; j < m1; j++)
            {
                a[x + i][y + j] += ops;
                a[x + i][y + j] %= k;
            }
        opcount += ops;
    }
}

int main()
{
    freopen("display.in", "r", stdin);
    freopen("display.out", "w", stdout);
    int k, opcount = 0;
    scanf("%d %d\n%d %d\n%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++)
        {
            step(i, j, k, opcount);
            if (!ver)
                break;
        }
    if (ver)
        printf("%d\n", opcount);
    else
        printf("impossible\n");
    return 0;
}
