#include <bits/stdc++.h>
using namespace std;
long long mod(long long a, long long b) {
  long long ans;
  if (b == 0)
    return -1;
  else {
    ans = (a < 0 ? mod(((a % b) + b), b) : a % b);
  }
  return ans;
}
vector<int> cntl(100003, 0), cntr(100003, 0), cntt(100003, 0), cntb(100003, 0);
int n, m, d;
void solve() {
  int cl, cb, cr, ct;
  cin >> d >> n >> m;
  vector<int> x1(d + 1), x2(d + 1), y1(d + 1), y2(d + 1);
  for (int i = 1; i < d + 1; i++) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    cntl[min(x1[i], x2[i])]++;
    cntr[max(x1[i], x2[i])]++;
    cntt[min(y1[i], y2[i])]++;
    cntb[max(y1[i], y2[i])]++;
  }
  for (int i = 1; i < 100003; i++) {
    cntl[i] += cntl[i - 1];
    cntt[i] += cntt[i - 1];
  }
  for (int i = 100001; i >= 1; i--) {
    cntb[i] += cntb[i + 1];
    cntr[i] += cntr[i + 1];
  }
  cin >> cl >> cr >> ct >> cb;
  vector<pair<pair<int, int>, pair<int, int> > > cnt(d);
  for (int i = 1; i < d + 1; i++) {
    cnt[i - 1].first.first = cntl[max(x1[i], x2[i]) - 1] - (x1[i] != x2[i]);
    cnt[i - 1].first.second = cntr[min(x1[i], x2[i]) + 1] - (x1[i] != x2[i]);
    cnt[i - 1].second.first = cntt[max(y1[i], y2[i]) - 1] - (y1[i] != y2[i]);
    cnt[i - 1].second.second = cntb[min(y1[i], y2[i]) + 1] - (y1[i] != y2[i]);
  }
  pair<pair<int, int>, pair<int, int> > target = {{cl, cr}, {ct, cb}};
  if (find((cnt).begin(), (cnt).end(), target) != cnt.end()) {
    cout << distance(cnt.begin(), find((cnt).begin(), (cnt).end(), target)) + 1
         << endl;
  } else
    cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
