#include <bits/stdc++.h>
using namespace std;
long long L[100005], R[100005], T[100005], B[100005];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long d, n, m;
  cin >> d >> n >> m;
  vector<long long> arr[d];
  for (long long i = 0; i < d; i++) {
    vector<long long> v(4);
    for (long long j = 0; j < 4; j++) cin >> v[j];
    L[min(v[0], v[2])]++;
    R[max(v[0], v[2])]++;
    T[min(v[1], v[3])]++;
    B[max(v[1], v[3])]++;
    arr[i] = v;
  }
  long long l, r, t, b;
  cin >> l >> r >> t >> b;
  for (long long i = 1; i <= n; i++) L[i] += L[i - 1];
  for (long long i = n - 1; i >= 0; i--) R[i] += R[i + 1];
  for (long long i = 1; i <= m; i++) T[i] += T[i - 1];
  for (long long i = m - 1; i >= 0; i--) B[i] += B[i + 1];
  for (long long i = 0; i < d; i++) {
    vector<long long> v = arr[i];
    long long l1 = L[max(v[0], v[2]) - 1];
    long long r1 = R[min(v[0], v[2]) + 1];
    long long t1 = T[max(v[1], v[3]) - 1];
    long long b1 = B[min(v[1], v[3]) + 1];
    if (v[0] != v[2]) l1--, r1--;
    if (v[1] != v[3]) t1--, b1--;
    if (l == l1 && b == b1 && t == t1 && r == r1) {
      cout << i + 1 << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
}
