#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 7;
int n, m, k, d, cntl, cntt, cntb, cntr;
int lx, rx, ty, by;
int L[MAX], R[MAX], T[MAX], B[MAX];
struct node {
  int l, r, b, t;
  node(int a = 0, int bb = 0, int c = 0, int d = 0) {
    l = min(a, c);
    r = max(a, c);
    b = min(bb, d);
    t = max(bb, d);
  }
};
node sofa[MAX];
signed main() {
  cin >> d >> n >> m;
  for (int i = 0; i < d; i++) {
    cin >> lx >> ty >> rx >> by;
    if (lx > rx) swap(lx, rx);
    if (by > ty) swap(ty, by);
    sofa[i] = {lx, ty, rx, by};
    L[i] = lx, R[i] = rx, T[i] = ty, B[i] = by;
  }
  sort(L, L + d), sort(R, R + d), sort(T, T + d), sort(B, B + d);
  cin >> cntl >> cntr >> cntt >> cntb;
  for (int i = 0; i < d; i++) {
    node x = sofa[i];
    lx = lower_bound(L, L + d, x.r) - L - (x.l < x.r);
    ty = lower_bound(B, B + d, x.t) - B - (x.b < x.t);
    rx = d - (upper_bound(R, R + d, x.l) - R) - (x.l < x.r);
    by = d - (upper_bound(T, T + d, x.b) - T) - (x.b < x.t);
    if (lx == cntl and rx == cntr and ty == cntt and by == cntb) {
      cout << i + 1 << "\n";
      exit(0);
    }
  }
  puts("-1");
  return 0;
}
