#include <bits/stdc++.h>
using namespace std;
const int INF = 522133279;
const int MAXN = 100000 + 100;
const int TOTN = 100 + 100;
const long long MOD = 1000000007;
int d, n, m;
int l[MAXN], r[MAXN], t[MAXN], b[MAXN];
struct rect {
  int x1, y1, x2, y2;
  rect() {}
  rect(int _x1, int _y1, int _x2, int _y2)
      : x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
} R[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin >> d;
  cin >> n >> m;
  for (int i = (0); i < (d); i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    l[min(x1, x2)]++;
    r[max(x1, x2)]++;
    t[min(y1, y2)]++;
    b[max(y1, y2)]++;
    R[i] = rect(x1, y1, x2, y2);
  }
  for (int i = (1); i < (n + 1); i++) {
    l[i] += l[i - 1];
  }
  for (int i = n - 1; i >= 0; i--) {
    r[i] += r[i + 1];
  }
  for (int i = (1); i < (m + 1); i++) {
    t[i] += t[i - 1];
  }
  for (int i = m - 1; i >= 0; i--) {
    b[i] += b[i + 1];
  }
  int cl, cr, ct, cb;
  cin >> cl >> cr >> ct >> cb;
  for (int i = (0); i < (d); i++) {
    if (cl + (R[i].x1 != R[i].x2) == l[max(R[i].x1, R[i].x2) - 1] &&
        cr + (R[i].x1 != R[i].x2) == r[min(R[i].x1, R[i].x2) + 1] &&
        ct + (R[i].y1 != R[i].y2) == t[max(R[i].y1, R[i].y2) - 1] &&
        cb + (R[i].y1 != R[i].y2) == b[min(R[i].y1, R[i].y2) + 1]) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
