#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::deque;
using std::endl;
using std::map;
using std::max;
using std::min;
using std::multiset;
using std::pair;
using std::queue;
using std::set;
using std::sort;
using std::stack;
using std::string;
using std::vector;
int main() {
  int data[51][51] = {
      0,
  };
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> data[i][j];
      data[i][j] += data[i][j - 1];
    }
  }
  int a, b;
  cin >> a >> b;
  int MIN1 = 3000;
  int MIN2 = 3000;
  if (a <= n && b <= m) {
    for (int startX = 1; startX + a - 1 <= n; startX++) {
      for (int startY = 1; startY + b - 1 <= m; startY++) {
        int sum = 0;
        for (int i = startX; i < startX + a; i++)
          sum += (data[i][startY + b - 1] - data[i][startY - 1]);
        MIN1 = min(MIN1, sum);
      }
    }
  }
  int temp = a;
  a = b;
  b = temp;
  if (a <= n && b <= m) {
    for (int startX = 1; startX + a - 1 <= n; startX++) {
      for (int startY = 1; startY + b - 1 <= m; startY++) {
        int sum = 0;
        for (int i = startX; i < startX + a; i++)
          sum += (data[i][startY + b - 1] - data[i][startY - 1]);
        MIN2 = min(MIN2, sum);
      }
    }
  }
  cout << min(MIN1, MIN2);
  return 0;
}
