#include <bits/stdc++.h>
using namespace std;
int mat[52][52], n, m, a, b;
int getsum(int urow, int ucol, int drow, int dcol) {
  int res = mat[drow][dcol];
  res = res - mat[urow - 1][dcol] - mat[drow][ucol - 1];
  res += mat[urow - 1][ucol - 1];
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &mat[i][j]);
  scanf("%d%d", &a, &b);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      mat[i][j] += mat[i][j - 1] + mat[i - 1][j] - mat[i - 1][j - 1];
    }
  int ans = n * m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      int dr = i + a - 1;
      int dc = j + b - 1;
      if (dr <= n && dc <= m) {
        int res = getsum(i, j, dr, dc);
        if (ans > res) ans = res;
      }
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      int dr = i + b - 1;
      int dc = j + a - 1;
      if (dr <= n && dc <= m) {
        int res = getsum(i, j, dr, dc);
        if (ans > res) ans = res;
      }
    }
  printf("%d\n", ans);
  return 0;
}
