#include <bits/stdc++.h>
using namespace std;
int d, n, m;
int cntl[100011], cntr[100011], cntt[100011], cntb[100011];
struct Sofa {
  int x1, y1, x2, y2;
} sofa[100011];
int main() {
  scanf("%d", &d);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < d; i++) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    cntl[min(x1, x2)]++;
    cntr[max(x1, x2)]++;
    cntt[min(y1, y2)]++;
    cntb[max(y1, y2)]++;
    sofa[i].x1 = x1;
    sofa[i].y1 = y1;
    sofa[i].x2 = x2;
    sofa[i].y2 = y2;
  }
  for (int i = 1; i <= n; i++) cntl[i] += cntl[i - 1];
  for (int i = n; i >= 0; i--) cntr[i] += cntr[i + 1];
  for (int i = 1; i <= m; i++) cntt[i] += cntt[i - 1];
  for (int i = m; i >= 0; i--) cntb[i] += cntb[i + 1];
  int tl, tr, tt, tb;
  scanf("%d %d %d %d", &tl, &tr, &tt, &tb);
  for (int i = 0; i < d; i++) {
    int tmpl = cntl[max(sofa[i].x1, sofa[i].x2) - 1],
        tmpr = cntr[min(sofa[i].x1, sofa[i].x2) + 1],
        tmpt = cntt[max(sofa[i].y1, sofa[i].y2) - 1],
        tmpb = cntb[min(sofa[i].y1, sofa[i].y2) + 1];
    if (max(sofa[i].x1, sofa[i].x2) != min(sofa[i].x1, sofa[i].x2)) {
      tmpl--;
      tmpr--;
    }
    if (max(sofa[i].y1, sofa[i].y2) != min(sofa[i].y1, sofa[i].y2)) {
      tmpt--;
      tmpb--;
    }
    if (tmpl == tl && tmpr == tr && tmpt == tt && tmpb == tb) {
      cout << i + 1;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
