#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int cnt, cur;
int N, X, Y;
bool up[MAXN], check[MAXN];
int kfjdkfj[MAXN], sfjdkf[MAXN];
int dfjdkfj[MAXN], fjdkf[MAXN];
vector<int> ordX[MAXN], ordY[MAXN];
int cntl, cntr, cntt, cntb;
bool goodl[MAXN], goodr[MAXN], goodt[MAXN], goodb[MAXN];
int main() {
  scanf("%d", &N);
  scanf("%d", &X), scanf("%d", &Y);
  for (int i = 0; i < (int)N; i++) {
    scanf("%d", &kfjdkfj[i]), scanf("%d", &sfjdkf[i]);
    scanf("%d", &dfjdkfj[i]), scanf("%d", &fjdkf[i]);
    if (kfjdkfj[i] == dfjdkfj[i]) up[i] = true;
  }
  scanf("%d", &cntl), scanf("%d", &cntr);
  scanf("%d", &cntb), scanf("%d", &cntt);
  for (int i = 0; i < (int)N; i++) {
    ordX[kfjdkfj[i]].push_back(i);
    if (!up[i]) ordX[dfjdkfj[i]].push_back(i);
    ordY[sfjdkf[i]].push_back(i);
    if (up[i]) ordY[fjdkf[i]].push_back(i);
  }
  cnt = 0;
  memset(check, false, sizeof(check));
  for (int x = 1; x < (int)X + 1; x++) {
    cur = 0;
    for (int i = 0; i < (int)ordX[x].size(); i++) {
      int idx = ordX[x][i];
      if (!check[idx]) cur++;
      check[idx] = true;
    }
    if (cnt == cntl || cnt == cntl + 1) {
      for (int i = 0; i < (int)ordX[x].size(); i++) {
        int idx = ordX[x][i];
        if (up[idx] && cnt == cntl)
          goodl[idx] = true;
        else if (!up[idx] && x >= kfjdkfj[idx] && x >= dfjdkfj[idx] &&
                 cnt == cntl + 1)
          goodl[idx] = true;
      }
    }
    cnt += cur;
  }
  cnt = 0;
  memset(check, false, sizeof(check));
  for (int x = X; x > (int)0; x--) {
    cur = 0;
    for (int i = 0; i < (int)ordX[x].size(); i++) {
      int idx = ordX[x][i];
      if (!check[idx]) cur++;
      check[idx] = true;
    }
    if (cnt == cntr || cnt == cntr + 1) {
      for (int i = 0; i < (int)ordX[x].size(); i++) {
        int idx = ordX[x][i];
        if (up[idx] && cnt == cntr)
          goodr[idx] = true;
        else if (!up[idx] && x <= kfjdkfj[idx] && x <= dfjdkfj[idx] &&
                 cnt == cntr + 1)
          goodr[idx] = true;
      }
    }
    cnt += cur;
  }
  cnt = 0;
  memset(check, false, sizeof(check));
  for (int y = 1; y < (int)Y + 1; y++) {
    cur = 0;
    for (int i = 0; i < (int)ordY[y].size(); i++) {
      int idx = ordY[y][i];
      if (!check[idx]) cur++;
      check[idx] = true;
    }
    if (cnt == cntb || cnt == cntb + 1) {
      for (int i = 0; i < (int)ordY[y].size(); i++) {
        int idx = ordY[y][i];
        if (!up[idx] && cnt == cntb)
          goodb[idx] = true;
        else if (up[idx] && y >= sfjdkf[idx] && y >= fjdkf[idx] &&
                 cnt == cntb + 1)
          goodb[idx] = true;
      }
    }
    cnt += cur;
  }
  cnt = 0;
  memset(check, false, sizeof(check));
  for (int y = Y; y > (int)0; y--) {
    cur = 0;
    for (int i = 0; i < (int)ordY[y].size(); i++) {
      int idx = ordY[y][i];
      if (!check[idx]) cur++;
      check[idx] = true;
    }
    if (cnt == cntt || cnt == cntt + 1) {
      for (int i = 0; i < (int)ordY[y].size(); i++) {
        int idx = ordY[y][i];
        if (!up[idx] && cnt == cntt)
          goodt[idx] = true;
        else if (up[idx] && y <= sfjdkf[idx] && y <= fjdkf[idx] &&
                 cnt == cntt + 1)
          goodt[idx] = true;
      }
    }
    cnt += cur;
  }
  for (int i = 0; i < (int)N; i++)
    if (goodl[i] && goodr[i] && goodb[i] && goodt[i]) {
      printf("%d\n", i + 1);
      return 0;
    }
  printf("%d\n", -1);
}
