/* GCC */
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#define MAXINPUT 1000

using namespace std;

void input();
void output(int SWAG = 0);

int n, m, p, q, k;
int d[MAXINPUT][MAXINPUT];

int main()
{
    freopen("display.in", "r", stdin);
    input();
    if (p*q == 1) {
        int w = 0;
        for (int j = 0; j < n; j++)
            for (int u = 0; u < m; u++) {
                w += d[j][u] == 0 ? 0 : k - d[j][u];
            }
        output(w);
    }

    if ((n*m) % (p*q) != 0)
        output();

    int w = 0;
    for (int j = 0; j < n; j++)
        for (int u = 0; u < m; u++)
            if (d[j][u] == k-1)
                w++;
    output(w);
}

void input()
{
    scanf("%d %d\n%d %d\n%d\n",
          &n, &m, &p, &q, &k);
    for (int j = 0; j < n; j++)
        for (int u = 0; u < m; u++)
            scanf("%d", &d[j][u]);
}

void output(int SWAG)
{
    freopen("display.out", "w", stdout);
    SWAG == 0 ? printf("impossible\n") : printf("%d\n", SWAG);
    exit(0);
}
