#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long N = 3e5 + 5;
const long long mod = 1e7 + 9;
const long double eps = 1E-7;
int k, n, m;
int a[N], b[N];
int x[N], y[N];
int l[N], r[N];
int u[N], d[N];
int l1, r1, l2, r2;
int a1, b1, a2, b2;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> k;
  cin >> n >> m;
  for (int i = 1; i <= k; i++) {
    cin >> a[i] >> b[i];
    cin >> x[i] >> y[i];
    if (a[i] > x[i]) swap(a[i], x[i]);
    if (b[i] > y[i]) swap(b[i], y[i]);
    l[a[i]]++;
    r[x[i]]++;
    u[b[i]]++;
    d[y[i]]++;
  }
  cin >> a1 >> b1;
  cin >> a2 >> b2;
  for (int i = 1; i <= max(n, m); i++) {
    int j = max(n, m) - i + 1;
    u[i] += u[i - 1], d[j] += d[j + 1];
    l[i] += l[i - 1], r[j] += r[j + 1];
  }
  for (int i = 1; i <= k; i++) {
    l1 = l[x[i] - 1] - (a[i] != x[i]);
    r1 = r[a[i] + 1] - (a[i] != x[i]);
    l2 = u[y[i] - 1] - (b[i] != y[i]);
    r2 = d[b[i] + 1] - (b[i] != y[i]);
    if (l1 == a1 && r1 == b1 && l2 == a2 && r2 == b2) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1;
}
