#include <bits/stdc++.h>
using namespace std;
pair<pair<int, int>, pair<int, int> > p[100005];
int main() {
  vector<int> my1, my2, my3, my4;
  int d;
  cin >> d;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < d; i++) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    p[i] = {{x1, y1}, {x2, y2}};
    my1.push_back(min(x1, x2));
    my3.push_back(max(x1, x2));
    my2.push_back(min(y1, y2));
    my4.push_back(max(y1, y2));
  }
  sort(my1.begin(), my1.end());
  sort(my2.begin(), my2.end());
  sort(my3.begin(), my3.end());
  sort(my4.begin(), my4.end());
  int cnt[4];
  for (int i = 0; i < 4; i++) cin >> cnt[i];
  for (int i = 0; i < d; i++) {
    int k[4] = {};
    int mn1 = min(p[i].first.first, p[i].second.first),
        mx1 = max(p[i].first.first, p[i].second.first);
    int mn2 = min(p[i].first.second, p[i].second.second),
        mx2 = max(p[i].first.second, p[i].second.second);
    int x1 = lower_bound(my1.begin(), my1.end(), mx1) - my1.begin();
    if (mn1 != mx1) x1--;
    k[0] += x1;
    x1 = d - (upper_bound(my3.begin(), my3.end(), mn1) - my3.begin());
    if (mn1 != mx1) x1--;
    k[1] += x1;
    x1 = lower_bound(my2.begin(), my2.end(), mx2) - my2.begin();
    if (mn2 != mx2) x1--;
    k[3] += x1;
    x1 = d - (upper_bound(my4.begin(), my4.end(), mn2) - my4.begin());
    if (mn2 != mx2) x1--;
    k[2] += x1;
    if (k[0] == cnt[0] && k[1] == cnt[1] && k[3] == cnt[2] && k[2] == cnt[3]) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
