#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int minx[N], maxx[N], miny[N], maxy[N];
int main() {
  int n;
  scanf("%d %*d %*d", &n);
  vector<tuple<int, int, int, int> > v;
  for (int i = 0; i < n; i++) {
    int xa, ya, xb, yb;
    scanf("%d %d %d %d", &xa, &ya, &xb, &yb);
    v.emplace_back(xa, ya, xb, yb);
    minx[min(xa, xb)]++;
    maxx[max(xa, xb)]++;
    miny[min(ya, yb)]++;
    maxy[max(ya, yb)]++;
  }
  for (int i = 1; i < N; i++) {
    minx[i] += minx[i - 1];
    maxx[i] += maxx[i - 1];
    miny[i] += miny[i - 1];
    maxy[i] += maxy[i - 1];
  }
  int cl, cr, ct, cb;
  scanf("%d %d %d %d", &cl, &cr, &ct, &cb);
  for (int i = 0; i < n; i++) {
    int xa, ya, xb, yb;
    tie(xa, ya, xb, yb) = v[i];
    int l = minx[max(xa, xb) - 1];
    if (xa != xb) l--;
    int r = maxx[N - 1] - maxx[min(xa, xb)];
    if (xa != xb) r--;
    int t = miny[max(ya, yb) - 1];
    if (ya != yb) t--;
    int b = maxy[N - 1] - maxy[min(ya, yb)];
    if (ya != yb) b--;
    if (l == cl and r == cr and t == ct and b == cb) {
      printf("%d\n", i + 1);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
