#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 5e5 + 5;
const int INF = 0x7fffffff;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
struct point {
  int x1, x2, y1, y2;
  int id;
} dat[maxn];
bool cmp1(point a, point b) { return min(a.x1, a.x2) < min(b.x1, b.x2); }
bool cmp2(point a, point b) { return max(a.x1, a.x2) > max(b.x1, b.x2); }
bool cmp3(point a, point b) { return min(a.y1, a.y2) < min(b.y1, b.y2); }
bool cmp4(point a, point b) { return max(a.y1, a.y2) > max(b.y1, b.y2); }
int n, m, d;
int l[maxn], r[maxn], t[maxn], b[maxn];
int cntl, cntr, cntt, cntb;
int c[maxn];
int main() {
  scanf("%d%d%d", &d, &n, &m);
  for (int i = 0; i < d; i++) {
    scanf("%d%d%d%d", &dat[i].x1, &dat[i].y1, &dat[i].x2, &dat[i].y2);
    if (dat[i].x1 > dat[i].x2) swap(dat[i].x1, dat[i].x2);
    if (dat[i].y1 > dat[i].y2) swap(dat[i].y1, dat[i].y2);
    dat[i].id = i;
  }
  scanf("%d%d%d%d", &cntl, &cntr, &cntt, &cntb);
  memset(c, 0, sizeof(c));
  ;
  for (int i = 0; i < d; i++) c[dat[i].x1]++;
  for (int i = 1; i < maxn; i++) c[i] = c[i - 1] + c[i];
  for (int i = 0; i < d; i++)
    if ((dat[i].x1 == dat[i].x2 && c[dat[i].x2 - 1] == cntl) ||
        (dat[i].x1 != dat[i].x2 && c[dat[i].x2 - 1] - 1 == cntl)) {
      l[i] = 1;
    }
  memset(c, 0, sizeof(c));
  ;
  for (int i = 0; i < d; i++) c[dat[i].x2]++;
  for (int i = maxn - 2; i >= 0; i--) c[i] = c[i + 1] + c[i];
  for (int i = 0; i < d; i++)
    if ((dat[i].x1 == dat[i].x2 && c[dat[i].x1 + 1] == cntr) ||
        (dat[i].x1 != dat[i].x2 && c[dat[i].x1 + 1] - 1 == cntr)) {
      r[i] = 1;
    }
  memset(c, 0, sizeof(c));
  ;
  for (int i = 0; i < d; i++) c[dat[i].y1]++;
  for (int i = 1; i < maxn; i++) c[i] = c[i - 1] + c[i];
  for (int i = 0; i < d; i++)
    if ((dat[i].y1 == dat[i].y2 && c[dat[i].y2 - 1] == cntt) ||
        (dat[i].y1 != dat[i].y2 && c[dat[i].y2 - 1] - 1 == cntt))
      t[i] = 1;
  memset(c, 0, sizeof(c));
  ;
  for (int i = 0; i < d; i++) c[dat[i].y2]++;
  for (int i = maxn - 2; i >= 0; i--) c[i] = c[i + 1] + c[i];
  for (int i = 0; i < d; i++)
    if ((dat[i].y1 == dat[i].y2 && c[dat[i].y1 + 1] == cntb) ||
        (dat[i].y1 != dat[i].y2 && c[dat[i].y1 + 1] - 1 == cntb))
      b[i] = 1;
  for (int i = 0; i < d; i++) {
    if (r[i] && l[i] && t[i] && b[i]) {
      printf("%d\n", i + 1);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
