#include <bits/stdc++.h>
using namespace std;
const long maxn = 55;
long mas[maxn][maxn];
long a, b, n, m, best;
void solve() {
  for (long choicex = 1; choicex <= n - a + 1; choicex++)
    for (long choicey = 1; choicey <= m - b + 1; choicey++) {
      long nnew = 0;
      for (long x = choicex; x <= choicex + a - 1; x++)
        for (long y = choicey; y <= choicey + b - 1; y++) nnew += mas[x][y];
      best = min(best, nnew);
    }
}
int main() {
  scanf("%ld%ld", &n, &m);
  long q, k;
  for (q = 1; q <= n; q++)
    for (k = 1; k <= m; k++) scanf("%ld", &mas[q][k]);
  scanf("%ld%ld", &a, &b);
  best = 10000000;
  solve();
  long temp = a;
  a = b;
  b = temp;
  solve();
  printf("%ld", best);
}
