#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50 + 10;
int H, W, lx, ly, val[MAXN][MAXN];
int main() {
  scanf("%d %d", &H, &W);
  for (int i = (0), iend = (H); i < iend; ++i)
    for (int j = (0), jend = (W); j < jend; ++j) scanf("%d", &val[i][j]);
  for (int i = (0), iend = (H); i < iend; ++i)
    for (int j = (0), jend = (W); j < jend; ++j) {
      val[i][j] += ((i > 0) ? val[i - 1][j] : 0) +
                   ((j > 0) ? val[i][j - 1] : 0) -
                   ((i > 0 && j > 0) ? val[i - 1][j - 1] : 0);
    }
  scanf("%d %d", &lx, &ly);
  int ans = INT_MAX;
  for (int i = (0), iend = (H - lx + 1); i < iend; ++i)
    for (int j = (0), jend = (W - ly + 1); j < jend; ++j) {
      ans = min(ans, val[i + lx - 1][j + ly - 1] -
                         ((i > 0) ? val[i - 1][j + ly - 1] : 0) -
                         ((j > 0) ? val[i + lx - 1][j - 1] : 0) +
                         ((i > 0 && j > 0) ? val[i - 1][j - 1] : 0));
    }
  swap(lx, ly);
  for (int i = (0), iend = (H - lx + 1); i < iend; ++i)
    for (int j = (0), jend = (W - ly + 1); j < jend; ++j) {
      ans = min(ans, val[i + lx - 1][j + ly - 1] -
                         ((i > 0) ? val[i - 1][j + ly - 1] : 0) -
                         ((j > 0) ? val[i + lx - 1][j - 1] : 0) +
                         ((i > 0 && j > 0) ? val[i - 1][j - 1] : 0));
    }
  printf("%d\n", ans);
  return 0;
}
