/* GCC */
#include <iostream>
using namespace std;
int main(){
    freopen("display.in", "r", stdin);
    freopen("display.out", "w", stdout);
    int m,n;
    scanf("%d %d", &n, &m);
    int n1, m1;
    scanf("%d %d", &n1, &m1);
    int x,k,s=0;
    scanf("%d", &k);
    int s1=k+1, rt=0;
    bool f=true;
    for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                 scanf("%d", &x);   
                 if(x!=0) s+=k-x;
                 if(s1==k+1){
                             s1=x;
                             if(x!=0) rt=k-x;
                 }
                 else{
                      if(x!=s1) f=false;
                 }
            }
    }
    if(n1==1 && m1==1) printf("%d\n", s);
    else{
         if(n==n1 && m==m1 && f) printf("%d\n", rt);
         else printf("impossible\n");
    }
    fclose(stdin);
    fclose(stdout);
}
