#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int inf = 0x7fffffff;
const int N = 1e5 + 7;
struct node {
  int id;
  int x1, y1, x2, y2;
} a[N];
void predeal(node &x) {
  if (x.x1 == x.x2) {
    if (x.y1 > x.y2) swap(x.y1, x.y2);
  }
  if (x.y1 == x.y2) {
    if (x.x1 > x.x2) swap(x.x1, x.x2);
  }
}
bool cmp1(node x, node y) {
  if (x.x2 != y.x2) return x.x2 < y.x2;
  return x.x1 < y.x1;
}
bool cmp2(node x, node y) {
  if (x.x1 != y.x1) return x.x1 > y.x1;
  return x.x2 > y.x2;
}
bool cmp3(node x, node y) {
  if (x.y2 != y.y2) return x.y2 < y.y2;
  return x.y1 < y.y1;
}
bool cmp4(node x, node y) {
  if (x.y1 != y.y1) return x.y1 > y.y1;
  return x.y2 > y.y2;
}
int num[N];
int main() {
  memset((num), (0), sizeof(num));
  int q;
  scanf("%d", &q);
  int n, m;
  scanf("%d%d", &n, &m);
  for (long long i = 1; i < 1 + q; i++) {
    a[i].id = i;
    scanf("%d%d", &a[i].x1, &a[i].y1);
    scanf("%d%d", &a[i].x2, &a[i].y2);
    predeal(a[i]);
  }
  int u, d, l, r;
  cin >> l >> r >> d >> u;
  sort(a + 1, a + q + 1, cmp1);
  for (long long i = 1; i < q + 1; i++) {
    if (a[l + 1].x1 == a[i].x1 && a[l + 1].x2 == a[i].x2) {
      num[a[i].id]++;
      if (i > l + 1 && a[i].x1 != a[i].x2) {
        cout << "-1";
        return 0;
      }
    }
  }
  sort(a + 1, a + 1 + q, cmp2);
  for (long long i = 1; i < q + 1; i++) {
    if (a[r + 1].x1 == a[i].x1 && a[r + 1].x2 == a[i].x2) {
      num[a[i].id]++;
      if (i > r + 1 && a[i].x2 != a[i].x1) {
        cout << "-1";
        return 0;
      }
    }
  }
  sort(a + 1, a + 1 + q, cmp3);
  for (long long i = 1; i < q + 1; i++) {
    if (a[d + 1].y1 == a[i].y1 && a[d + 1].y2 == a[i].y2) {
      num[a[i].id]++;
      if (i > d + 1 && a[i].y1 != a[i].y2) {
        cout << "-1";
        return 0;
      }
    }
  }
  sort(a + 1, a + 1 + q, cmp4);
  for (long long i = 1; i < q + 1; i++) {
    if (a[u + 1].y1 == a[i].y1 && a[u + 1].y2 == a[i].y2) {
      num[a[i].id]++;
      if (i > u + 1 && a[i].y1 != a[i].y2) {
        cout << "-1";
        return 0;
      }
    }
  }
  int ans = -1;
  for (long long i = 1; i < q + 1; i++)
    if (num[i] == 4) ans = i;
  printf("%d\n", ans);
  return 0;
}
