#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long double PI = 3.14159265;
long long int powerWithMod(long long int base, long long int exponent,
                           long long int modulus = LLONG_MAX) {
  long long int result = 1;
  base %= modulus;
  while (exponent > 0) {
    if (exponent % 2 == 1) result = (result * base) % modulus;
    exponent >>= 1;
    base = (base * base) % modulus;
  }
  return result;
}
long long int modInverse(long long int a, long long int m = MOD) {
  return powerWithMod(a, m - 2, m);
}
struct sofa {
  pair<int, int> x, y;
};
const int MAXN = 1e5;
int d, n, m, cntl, cntr, cntu, cntd, p, q, r, s, l[MAXN], rt[MAXN], u[MAXN],
    down[MAXN];
sofa a[MAXN];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> d >> n >> m;
  for (int i = 0; i < d; i++) {
    cin >> p >> q >> r >> s;
    l[i] = min(p, r);
    rt[i] = max(p, r);
    u[i] = min(q, s);
    down[i] = max(q, s);
    a[i].x = {p, q};
    a[i].y = {r, s};
  }
  cin >> cntl >> cntr >> cntu >> cntd;
  sort(l, l + d);
  sort(rt, rt + d);
  sort(u, u + d);
  sort(down, down + d);
  for (int i = 0; i < d; i++) {
    p = max(a[i].x.first, a[i].y.first);
    p = lower_bound(l, l + d, p) - l;
    if (a[i].x.first != a[i].y.first) p--;
    if (p != cntl) continue;
    p = min(a[i].x.first, a[i].y.first);
    p = upper_bound(rt, rt + d, p) - rt;
    p = d - p;
    if (a[i].x.first != a[i].y.first) p--;
    if (p != cntr) continue;
    p = max(a[i].x.second, a[i].y.second);
    p = lower_bound(u, u + d, p) - u;
    if (a[i].x.second != a[i].y.second) p--;
    if (p != cntu) continue;
    p = min(a[i].x.second, a[i].y.second);
    p = upper_bound(down, down + d, p) - down;
    p = d - p;
    if (a[i].x.second != a[i].y.second) p--;
    if (p != cntd) continue;
    cout << i + 1 << "\n";
    return 0;
  }
  cout << "-1\n";
  return 0;
}
