#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 4;
int r[MAX], l[MAX], t[MAX], b[MAX];
pair<pair<int, int>, pair<int, int> > arr[MAX];
void update(int* ar, int idx) {
  for (int i = idx; i < MAX; i += (i & -i)) {
    ar[i] += 1;
  }
}
int read(int* ar, int idx) {
  int sum = 0;
  for (int i = idx; i > 0; i -= (i & -i)) {
    sum += ar[i];
  }
  return sum;
}
int main() {
  int d, X, Y, L, R, T, B;
  cin >> d >> X >> Y;
  int x[2], y[2];
  for (int i = 0; i < d; ++i) {
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    sort(x, x + 2);
    sort(y, y + 2);
    update(r, x[1]);
    update(l, x[0]);
    update(t, y[0]);
    update(b, y[1]);
    arr[i] = {{x[0], x[1]}, {y[0], y[1]}};
  }
  cin >> L >> R >> T >> B;
  for (int i = 0; i < d; ++i) {
    int x0 = arr[i].first.first, x1 = arr[i].first.second,
        y0 = arr[i].second.first, y1 = arr[i].second.second;
    if (x0 == x1) {
      if (read(l, x1 - 1) == L)
        ;
      else
        continue;
    } else {
      if (read(l, x1 - 1) - 1 == L)
        ;
      else
        continue;
    }
    if (x0 == x1) {
      if (read(r, MAX - 2) - read(r, x0) == R)
        ;
      else
        continue;
    } else {
      if (read(r, MAX - 2) - read(r, x0) - 1 == R)
        ;
      else
        continue;
    }
    if (y0 == y1) {
      if (read(t, y1 - 1) == T)
        ;
      else
        continue;
    } else {
      if (read(t, y1 - 1) - 1 == T)
        ;
      else
        continue;
    }
    if (y0 == y1) {
      if (read(b, MAX - 2) - read(b, y0) == B)
        ;
      else
        continue;
    } else {
      if (read(b, MAX - 2) - read(b, y0) - 1 == B)
        ;
      else
        continue;
    }
    cout << i + 1 << endl;
    return 0;
  }
  cout << "-1\n";
  return 0;
}
