#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int d, n, m, i, j, k;
  cin >> d >> n >> m;
  int p, q, r1, s, a, c;
  int x[d], x1[d], y[d], y1[d];
  int c1, c2, c3, c4;
  int f1, f2, f3, f4;
  int l[n + 2], r[n + 2], t[m + 2], b[m + 2];
  for (i = 0; i <= m + 1; i++) t[i] = b[i] = 0;
  for (i = 0; i <= n + 1; i++) l[i] = r[i] = 0;
  for (i = 0; i < d; i++) {
    cin >> p >> q >> r1 >> s;
    x[i] = p;
    x1[i] = r1;
    y[i] = q;
    y1[i] = s;
    l[min(p, r1)]++;
    r[max(p, r1)]++;
    t[max(q, s)]++;
    b[min(q, s)]++;
  }
  cin >> c1 >> c2 >> c3 >> c4;
  for (i = 2; i <= n; i++) {
    l[i] += l[i - 1];
  }
  for (i = 2; i <= m; i++) {
    b[i] += b[i - 1];
  }
  for (i = n - 1; i >= 1; i--) {
    r[i] += r[i + 1];
  }
  for (i = m - 1; i >= 1; i--) {
    t[i] += t[i + 1];
  }
  for (i = 0; i < d; i++) {
    p = x[i];
    q = x1[i];
    r1 = y[i];
    s = y1[i];
    f1 = l[max(p, q) - 1];
    f2 = r[min(p, q) + 1];
    f4 = t[min(r1, s) + 1];
    f3 = b[max(r1, s) - 1];
    if (p == q)
      f3--, f4--;
    else
      f1--, f2--;
    if (f1 == c1 && f2 == c2 && f3 == c3 && f4 == c4) {
      cout << i + 1;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
