#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, u, d, id;
  int cntl, cntr, cntu, cntd;
} s[100010];
bool cmpd(const node& a, const node& b) { return a.d < b.d; }
bool cmpr(const node& a, const node& b) { return a.r < b.r; }
bool cmpu(const node& a, const node& b) { return a.u > b.u; }
bool cmpl(const node& a, const node& b) { return a.l > b.l; }
int main() {
  int d;
  scanf("%d", &d);
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= d; i++) {
    int l, u, r, d;
    scanf("%d %d %d %d", &l, &u, &r, &d);
    if (l > r) swap(l, r);
    if (u > d) swap(u, d);
    s[i] = {l, r, u, d, i};
  }
  sort(s + 1, s + 1 + d, cmpd);
  priority_queue<int, vector<int>, greater<int>> q;
  for (int i = 1; i <= d; i++) {
    q.push(s[i].u);
  }
  for (int i = 1; i <= d; i++) {
    while (q.size() && q.top() < s[i].d) {
      q.pop();
    }
    s[i].cntu = d - q.size();
    if (s[i].u != s[i].d) s[i].cntu--;
  }
  while (q.size()) q.pop();
  sort(s + 1, s + 1 + d, cmpr);
  for (int i = 1; i <= d; i++) {
    q.push(s[i].l);
  }
  for (int i = 1; i <= d; i++) {
    while (q.size() && q.top() < s[i].r) {
      q.pop();
    }
    s[i].cntl = d - q.size();
    if (s[i].l != s[i].r) s[i].cntl--;
  }
  priority_queue<int> Q;
  sort(s + 1, s + 1 + d, cmpl);
  for (int i = 1; i <= d; i++) {
    Q.push(s[i].r);
  }
  for (int i = 1; i <= d; i++) {
    while (Q.size() && Q.top() > s[i].l) {
      Q.pop();
    }
    s[i].cntr = d - Q.size();
    if (s[i].l != s[i].r) s[i].cntr--;
  }
  while (Q.size()) Q.pop();
  sort(s + 1, s + 1 + d, cmpu);
  for (int i = 1; i <= d; i++) {
    Q.push(s[i].d);
  }
  for (int i = 1; i <= d; i++) {
    while (Q.size() && Q.top() > s[i].u) {
      Q.pop();
    }
    s[i].cntd = d - Q.size();
    if (s[i].u != s[i].d) s[i].cntd--;
  }
  int cntl, cntr, cntu, cntd;
  cin >> cntl >> cntr >> cntu >> cntd;
  for (int i = 1; i <= d; i++) {
    if (s[i].cntl == cntl && s[i].cntr == cntr && s[i].cntu == cntu &&
        s[i].cntd == cntd) {
      printf("%d\n", s[i].id);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
