#include <bits/stdc++.h>
using namespace std;
int d, n, m;
int cntl, cntr, cntu, cntd;
int U[1000001], D[1000001], L[1000001], R[1000001];
struct sofa {
  int u, d, l, r;
} a[1000000];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> d >> n >> m;
  for (int i = 0; i < d; i++) {
    int L, U, R, D;
    cin >> L >> U >> R >> D;
    if (L > R) swap(L, R);
    if (U > D) swap(U, D);
    a[i].u = U;
    a[i].d = D;
    a[i].l = L;
    a[i].r = R;
    ::U[U]++;
    ::L[L]++;
    ::R[R]++;
    ::D[D]++;
  }
  cin >> cntl >> cntr >> cntu >> cntd;
  for (int i = 1; i <= 1000000; i++) {
    U[i] += U[i - 1];
    D[1000000 - i] += D[1000000 - i + 1];
    L[i] += L[i - 1];
    R[1000000 - i] += R[1000000 - i + 1];
  }
  for (int i = 0; i < d; i++) {
    if ((R[a[i].l + 1] - (a[i].l != a[i].r)) == cntr &&
        (L[a[i].r - 1] - (a[i].l != a[i].r)) == cntl &&
        (U[a[i].d - 1] - (a[i].u != a[i].d)) == cntu &&
        (D[a[i].u + 1] - (a[i].d != a[i].u)) == cntd) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
