#include <bits/stdc++.h>
using namespace std;
const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int MR = 1e5 + 10;
pair<pair<int, int>, int> ss[2][MR];
pair<pair<int, int>, pair<int, int>> s[MR];
vector<int> res[MR];
int main() {
  int d, n, m;
  scanf("%d%d%d", &d, &n, &m);
  for (int i = 0; i < (d); ++i) {
    scanf("%d%d%d%d", &s[i].first.first, &s[i].second.first, &s[i].first.second,
          &s[i].second.second);
    if (s[i].first.first < s[i].first.second)
      swap(s[i].first.first, s[i].first.second);
    if (s[i].second.first < s[i].second.second)
      swap(s[i].second.first, s[i].second.second);
    ss[0][i] = make_pair(s[i].first, i);
    ss[1][i] = make_pair(s[i].second, i);
  }
  int l, r, t, b;
  scanf("%d%d%d%d", &l, &r, &t, &b);
  for (int c = 0; c < (2); ++c) {
    sort(ss[c], ss[c] + d);
    for (int i = 0; i < (d); ++i) {
      int cnt1, cnt2;
      if (ss[c][i].first.first > ss[c][i].first.second) {
        cnt1 = upper_bound(ss[c], ss[c] + d, make_pair(ss[c][i].first, MR)) -
               ss[c] - 1;
        cnt2 =
            d - cnt1 - 1 +
            (upper_bound(ss[c], ss[c] + d, make_pair(ss[c][i].first, MR)) -
             lower_bound(ss[c], ss[c] + d, make_pair(ss[c][i].first, -1)) - 1);
      } else {
        cnt1 = lower_bound(ss[c], ss[c] + d, make_pair(ss[c][i].first, -1)) -
               ss[c];
        cnt2 =
            d - (upper_bound(ss[c], ss[c] + d, make_pair(ss[c][i].first, MR)) -
                 ss[c]);
      }
      res[ss[c][i].second].push_back(cnt1);
      res[ss[c][i].second].push_back(cnt2);
    }
  }
  int ind = -1;
  vector<int> cmp = {l, r, t, b};
  for (int i = 0; i < (d); ++i)
    if (res[i] == cmp) {
      ind = i + 1;
      break;
    }
  printf("%d\n", ind);
  return 0;
}
