#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
const double eps = 1e-8;
using namespace std;
int d, n, m;
int T[100024], L[100024], R[100024], B[100024];
int cntl = 0, cntr = 0, cntt = 0, cntb = 0;
struct P {
  int x1, x2, y1, y2;
  P(int _x1, int _y1, int _x2, int _y2) {
    x1 = _x1;
    y1 = _y1;
    x2 = _x2;
    y2 = _y2;
  }
  P() {}
} p[100024];
int main() {
  scanf("%d%d%d", &d, &n, &m);
  memset(T, 0, sizeof(T));
  memset(B, 0, sizeof(B));
  memset(L, 0, sizeof(L));
  memset(R, 0, sizeof(R));
  int x1, y1, x2, y2;
  for (int i = 0; i < d; i++) {
    cin >> x1 >> y1 >> x2 >> y2;
    p[i] = P(x1, y1, x2, y2);
    int ml = min(x1, x2), mr = max(x1, x2);
    int mt = min(y1, y2), mb = max(y1, y2);
    L[ml + 1]++;
    R[mr - 1]++;
    T[mt + 1]++;
    B[mb - 1]++;
  }
  for (int i = 2; i <= n; i++) L[i] += L[i - 1];
  for (int i = 2; i <= m; i++) T[i] += T[i - 1];
  for (int i = n - 1; i >= 1; i--) R[i] += R[i + 1];
  for (int i = m - 1; i >= 1; i--) B[i] += B[i + 1];
  scanf("%d%d%d%d", &cntl, &cntr, &cntt, &cntb);
  int sum = 0;
  for (int i = 0; i < d; i++) {
    int ml = min(p[i].x1, p[i].x2), mr = max(p[i].x1, p[i].x2);
    int mt = min(p[i].y1, p[i].y2), mb = max(p[i].y1, p[i].y2);
    int numl = L[mr], numr = R[ml], numt = T[mb], numb = B[mt];
    if (p[i].x1 != p[i].x2)
      numl--, numr--;
    else
      numt--, numb--;
    if (numl == cntl && numr == cntr && numt == cntt && numb == cntb)
      sum = i + 1;
  }
  if (sum == 0)
    printf("-1");
  else
    printf("%d", sum);
  return 0;
}
