#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int fsx[N], fsy[N], scx[N], scy[N];
int lcnt[N];
int rcnt[N];
int ucnt[N];
int dcnt[N];
int main() {
  int d;
  int n, m;
  scanf("%d%d%d", &d, &n, &m);
  for (int i = 0; i < d; ++i) {
    scanf("%d%d%d%d", &fsx[i], &fsy[i], &scx[i], &scy[i]);
    ++lcnt[min(fsx[i], scx[i])];
    ++rcnt[max(fsx[i], scx[i])];
    ++ucnt[min(fsy[i], scy[i])];
    ++dcnt[max(fsy[i], scy[i])];
  }
  for (int i = 1; i < N; ++i) {
    lcnt[i] += lcnt[i - 1];
    ucnt[i] += ucnt[i - 1];
  }
  for (int i = N - 2; i >= 0; --i) {
    rcnt[i] += rcnt[i + 1];
    dcnt[i] += dcnt[i + 1];
  }
  int wl, wr, wd, wu;
  scanf("%d%d%d%d", &wl, &wr, &wu, &wd);
  for (int i = 0; i < d; ++i) {
    int cl, cr, cd, cu;
    cl = lcnt[max(fsx[i], scx[i]) - 1];
    cr = rcnt[min(fsx[i], scx[i]) + 1];
    if (fsx[i] != scx[i]) --cl, --cr;
    cu = ucnt[max(fsy[i], scy[i]) - 1];
    cd = dcnt[min(fsy[i], scy[i]) + 1];
    if (fsy[i] != scy[i]) --cu, --cd;
    if (wl == cl && wr == cr && wd == cd && wu == cu) {
      printf("%d\n", i + 1);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
