#include <bits/stdc++.h>
using namespace std;
long long da, n, m, l[100010], r[100010], u[100010], d[100010], y[100010],
    x[100010], x2[100010], y2[100010];
int main() {
  scanf("%lld %lld %lld", &da, &n, &m);
  for (int i = 0; i < da; ++i) {
    scanf("%lld %lld %lld %lld", &x[i], &y[i], &x2[i], &y2[i]);
    if (x[i] > x2[i]) swap(x[i], x2[i]);
    if (y[i] > y2[i]) swap(y[i], y2[i]);
    l[y[i]]++;
    r[y2[i]]++;
    u[x[i]]++;
    d[x2[i]]++;
  }
  long long cr, cl, cu, cd;
  cin >> cu >> cd >> cl >> cr;
  for (int i = 1; i < 100000; ++i) l[i] += l[i - 1];
  for (int i = 100000; i >= 1; --i) r[i] += r[i + 1];
  for (int i = 100000; i >= 1; --i) d[i] += d[i + 1];
  for (int i = 1; i < 100000; ++i) u[i] += u[i - 1];
  for (int i = 0; i < da; i++) {
    if (l[y2[i] - 1] - (y[i] != y2[i]) == cl &&
        r[y[i] + 1] - (y[i] != y2[i]) == cr &&
        u[x2[i] - 1] - (x[i] != x2[i]) == cu &&
        d[x[i] + 1] - (x[i] != x2[i]) == cd) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
