#include <bits/stdc++.h>
using namespace std;
int n, m;
int a, b;
int t[50][50];
int check(int sa, int sb, int ea, int eb) {
  int sum = 0;
  for (int i = sa; i < ea; ++i)
    for (int j = sb; j < eb; ++j) sum += t[i][j];
  return sum;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> t[i][j];
  cin >> a >> b;
  int res = 987654321;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (i + a <= n && j + b <= m) res = min(res, check(i, j, i + a, j + b));
      if (i + b <= n && j + a <= m) res = min(res, check(i, j, i + b, j + a));
    }
  cout << res << endl;
  return 0;
}
