#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int N, M, X, Y, MIN;
int A[MAXN][MAXN];
int Sum[MAXN][MAXN];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      scanf("%d", &A[i][j]);
      Sum[i][j] = Sum[i - 1][j] + Sum[i][j - 1] - Sum[i - 1][j - 1] + A[i][j];
    }
  }
  scanf("%d%d", &X, &Y);
  MIN = N * M;
  for (int i = X; i <= N; i++) {
    for (int j = Y; j <= M; j++) {
      MIN = min(MIN,
                Sum[i][j] - Sum[i - X][j] - Sum[i][j - Y] + Sum[i - X][j - Y]);
    }
  }
  swap(X, Y);
  for (int i = X; i <= N; i++) {
    for (int j = Y; j <= M; j++) {
      MIN = min(MIN,
                Sum[i][j] - Sum[i - X][j] - Sum[i][j - Y] + Sum[i - X][j - Y]);
    }
  }
  printf("%d\n", MIN);
  return 0;
}
