#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, n1, m1, a[51][51], b[51][51];
  vector<int> ans;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  cin >> n1 >> m1;
  if (n1 <= n && m1 <= m) {
    for (int x = 0; x <= (n - n1); ++x) {
      for (int y = 0; y <= (m - m1); ++y) {
        int ot = 0;
        for (int i = 0; i < n1; ++i) {
          for (int j = 0; j < m1; ++j) {
            ot += a[i + x][j + y];
          }
        }
        ans.push_back(ot);
      }
    }
  }
  swap(n1, m1);
  if (n1 <= n && m1 <= m) {
    for (int x = 0; x <= (n - n1); ++x) {
      for (int y = 0; y <= (m - m1); ++y) {
        int ot = 0;
        for (int i = 0; i < n1; ++i) {
          for (int j = 0; j < m1; ++j) {
            ot += a[i + x][j + y];
          }
        }
        ans.push_back(ot);
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans[0];
  return 0;
}
