#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int n, m, A[55][55], a, b, ans = 2e9, pre[55][55];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
      if (i == 0 && j == 0)
        pre[i][j] = A[i][j];
      else if (i == 0)
        pre[i][j] = pre[i][j - 1] + A[i][j];
      else if (j == 0)
        pre[i][j] = pre[i - 1][j] + A[i][j];
      else
        pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1] + A[i][j];
    }
  }
  cin >> a >> b;
  for (int i = 0; i < n - a + 1; i++) {
    for (int j = 0; j < m - b + 1; j++) {
      if (i == 0 && j == 0)
        ans = min(ans, pre[i + a - 1][j + b - 1]);
      else if (i == 0)
        ans = min(ans, pre[i + a - 1][j + b - 1] - pre[i + a - 1][j - 1]);
      else if (j == 0)
        ans = min(ans, pre[i + a - 1][j + b - 1] - pre[i - 1][j + b - 1]);
      else
        ans = min(ans, pre[i + a - 1][j + b - 1] - pre[i - 1][j + b - 1] -
                           pre[i + a - 1][j - 1] + pre[i - 1][j - 1]);
    }
  }
  for (int i = 0; i < n - b + 1; i++) {
    for (int j = 0; j < m - a + 1; j++) {
      if (i == 0 && j == 0)
        ans = min(ans, pre[i + b - 1][j + a - 1]);
      else if (i == 0)
        ans = min(ans, pre[i + b - 1][j + a - 1] - pre[i + b - 1][j - 1]);
      else if (j == 0)
        ans = min(ans, pre[i + b - 1][j + a - 1] - pre[i - 1][j + a - 1]);
      else
        ans = min(ans, pre[i + b - 1][j + a - 1] - pre[i - 1][j + a - 1] -
                           pre[i + b - 1][j - 1] + pre[i - 1][j - 1]);
    }
  }
  cout << ans << endl;
  return 0;
}
