#include <bits/stdc++.h>
using namespace std;
int mat[100][100];
int dp[100][100];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) cin >> mat[i][j];
  int n, m;
  cin >> n >> m;
  int mi = 1000000000;
  for (int i = 1; i <= N; ++i) {
    dp[i][1] = mat[i - 1][0];
    for (int j = 1; j <= M; ++j) {
      dp[i][j] = dp[i][j - 1] + mat[i - 1][j - 1];
    }
    for (int j = 1; j <= M; ++j) {
      dp[i][j] += dp[i - 1][j];
      if (i >= n && j >= m)
        mi = min(dp[i][j] - dp[i - n][j] - dp[i][j - m] + dp[i - n][j - m], mi);
      if (j >= n && i >= m)
        mi = min(dp[i][j] - dp[i - m][j] - dp[i][j - n] + dp[i - m][j - n], mi);
    }
    cout << endl;
  }
  cout << mi << endl;
}
