#include <bits/stdc++.h>
using namespace std;
struct {
  int minx, maxx, miny, maxy;
} s[100010];
int minl[100010], maxr[100010], mint[100010], maxb[100010], l, r, t, b, n, m, o;
int main() {
  scanf("%d", &o);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= o; i++) {
    int x1, x2, y1, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    s[i].minx = min(x1, x2);
    s[i].maxx = max(x1, x2);
    s[i].miny = min(y1, y2);
    s[i].maxy = max(y1, y2);
    minl[s[i].minx]++;
    maxr[s[i].maxx]++;
    mint[s[i].miny]++;
    maxb[s[i].maxy]++;
  }
  for (int i = 1; i <= n; i++) {
    minl[i] += minl[i - 1];
    maxr[n - i + 1] += maxr[n - i + 2];
  }
  for (int i = 1; i <= m; i++) {
    mint[i] += mint[i - 1];
    maxb[m - i + 1] += maxb[m - i + 2];
  }
  int k = -1;
  scanf("%d%d%d%d", &l, &r, &t, &b);
  for (int i = 1; i <= o; i++) {
    int lx, rx, ty, by;
    lx = (s[i].maxx == s[i].minx) ? minl[s[i].maxx - 1]
                                  : minl[s[i].maxx - 1] - 1;
    rx = (s[i].maxx == s[i].minx) ? maxr[s[i].minx + 1]
                                  : maxr[s[i].minx + 1] - 1;
    ty = (s[i].maxy == s[i].miny) ? mint[s[i].maxy - 1]
                                  : mint[s[i].maxy - 1] - 1;
    by = (s[i].maxy == s[i].miny) ? maxb[s[i].miny + 1]
                                  : maxb[s[i].miny + 1] - 1;
    if (lx == l && rx == r && ty == t && by == b) {
      k = i;
      break;
    }
  }
  cout << k;
  return 0;
}
