#include <bits/stdc++.h>
using namespace std;
int D, n, m, x1[100005], x2[100005], yiuoi[100005], y2[100005], lc[100005],
    rc[100005], tc[100005], dc[100005];
vector<pair<int, int> > asdyiuoi[100005], qasdsasdyiuoi[100005], top[100005],
    down[100005];
void solve() {
  cin >> D >> n >> m;
  for (int i = 0; i < D; i++) cin >> x1[i] >> yiuoi[i] >> x2[i] >> y2[i];
  for (int i = 0; i < D; i++) {
    asdyiuoi[min(x1[i], x2[i])].push_back({max(x1[i], x2[i]), i});
    qasdsasdyiuoi[max(x1[i], x2[i])].push_back({min(x1[i], x2[i]), i});
    top[max(yiuoi[i], y2[i])].push_back({min(yiuoi[i], y2[i]), i});
    down[min(yiuoi[i], y2[i])].push_back({max(yiuoi[i], y2[i]), i});
  }
  int l = 0, d = 0;
  for (int i = 0; i < 100001; i++) {
    for (auto j : asdyiuoi[i]) {
      if (j.first == i + 1)
        lc[j.second] += l + (int)asdyiuoi[i].size() - 1;
      else
        lc[j.second] += l;
    }
    for (auto j : down[i]) {
      if (j.first == i + 1)
        dc[j.second] += d + (int)down[i].size() - 1;
      else
        dc[j.second] += d;
    }
    l += (int)asdyiuoi[i].size();
    d += (int)down[i].size();
  }
  int r = 0, t = 0;
  for (int i = 100000; i >= 0; i--) {
    for (auto j : qasdsasdyiuoi[i]) {
      if (j.first == i - 1)
        rc[j.second] += r + (int)qasdsasdyiuoi[i].size() - 1;
      else
        rc[j.second] += r;
    }
    for (auto j : top[i]) {
      if (j.first == i - 1)
        tc[j.second] += t + (int)top[i].size() - 1;
      else
        tc[j.second] += t;
    }
    r += (int)qasdsasdyiuoi[i].size();
    t += (int)top[i].size();
  }
  int L, R, T, DD;
  cin >> L >> R >> DD >> T;
  for (int i = 0; i < D; i++) {
    if (lc[i] == L and rc[i] == R and tc[i] == T and dc[i] == DD) {
      cout << i + 1 << '\n';
      return;
    }
  }
  cout << -1 << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
