#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int d;
int n, m;
int l, r, t, b;
int ll[maxn], rr[maxn], tt[maxn], bb[maxn];
struct sofa {
  int x1, y1, x2, y2;
  int id;
} sf[maxn];
int main() {
  cin >> d;
  cin >> n >> m;
  for (int i = 0; i < d; i++) {
    scanf("%d %d %d %d", &sf[i].x1, &sf[i].y1, &sf[i].x2, &sf[i].y2);
    if (sf[i].x1 > sf[i].x2) {
      swap(sf[i].x1, sf[i].x2);
    }
    if (sf[i].y1 > sf[i].y2) {
      swap(sf[i].y1, sf[i].y2);
    }
    ll[sf[i].x1]++;
    rr[sf[i].x2]++;
    tt[sf[i].y1]++;
    bb[sf[i].y2]++;
  }
  cin >> l >> r >> t >> b;
  for (int i = 1; i <= n; i++) {
    ll[i] += ll[i - 1];
  }
  for (int i = n; i >= 1; i--) {
    rr[i] += rr[i + 1];
  }
  for (int i = 1; i <= m; i++) {
    tt[i] += tt[i - 1];
  }
  for (int i = m; i >= 1; i--) {
    bb[i] += bb[i + 1];
  }
  for (int i = 0; i < d; i++) {
    if (ll[sf[i].x2 - 1] - (sf[i].x1 != sf[i].x2) == l &&
        rr[sf[i].x1 + 1] - (sf[i].x1 != sf[i].x2) == r &&
        tt[sf[i].y2 - 1] - (sf[i].y1 != sf[i].y2) == t &&
        bb[sf[i].y1 + 1] - (sf[i].y1 != sf[i].y2) == b) {
      printf("%d\n", i + 1);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
