{ Free Pascal }
Var
  i,j,k,i1,j1,n,m,n1,m1,kil:longint;
  display:array[1..1001,1..1001]of longint;
  inp,outp:text;
  bol:boolean;
  ans:boolean;
Begin
  Assign(inp,'display.in');
  Assign(outp,'display.out');
  Reset(inp);
  Rewrite(outp);
  Readln(inp,n,m);
  Readln(inp,n1,m1);
  Readln(inp,k);
  for i:=1 to n do
  for j:=1 to m do
  Read(inp,display[i,j]);
  i:=1;
  j:=1;
  kil:=0;
  bol:=false;
  ans:=false;
  While bol=false do
  Begin
    if display[i,j]=0 then
    Begin
      if i=n then
      Begin
        if j=m then
        Begin
          bol:=true;
          ans:=true;
        End
        else
        Begin
          inc(j);
        End;
      End
      else
      Begin
        if j=m then
        Begin
          inc(i);
          j:=1;
        End
        else
        Begin
          inc(j);
        End;
      End;
    End
    else
    Begin
      if i+n1-1<=n then
      Begin
        if j+m1-1<=m then
        Begin
          for i1:=i to i+n1-1 do
          for j1:=j to j+m1-1 do
          Begin
            display[i1,j1]:=(display[i1,j1]+1) mod k;
          End;
          inc(kil);
        End
        else
        Begin
          bol:=true;
          ans:=false;
        End;
      End
      else
      Begin
        bol:=true;
        ans:=false;
      End;
    End;
  End;
  if ans=true then
  Begin
    Writeln(outp,kil);
  End
  else
  Begin
    Writeln(outp,'impossible');
  End;
  Close(inp);
  Close(outp);
End.