#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int g[51][51];
void swap() {
  int temp = a;
  a = b;
  b = temp;
}
int solve() {
  int res = n * m;
  for (int it = 0; it < 2; it++) {
    if (a <= n && b <= m) {
      for (int r = 1; r <= n - a + 1; r++) {
        for (int c = 1; c <= m - b + 1; c++) {
          int x1 = g[r + a - 1][c + b - 1];
          int x2 = g[r - 1][c + b - 1];
          int x3 = g[r + a - 1][c - 1];
          int x4 = g[r - 1][c - 1];
          res = min(res, x1 - x2 - x3 + x4);
        }
      }
    }
    swap();
  }
  return res;
}
int main() {
  int res = 0;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &g[i][j]);
      int x1 = g[i - 1][j];
      int x2 = g[i][j - 1];
      int x3 = g[i - 1][j - 1];
      g[i][j] += x1 + x2 - x3;
    }
  }
  scanf("%d %d", &a, &b);
  res = solve();
  printf("%d\n", res);
  return 0;
}
