#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
  out << "[";
  for (auto it = a.begin(); it != a.end(); ++it) {
    if (it != a.begin()) out << ", ";
    out << *it;
  }
  return out << "]";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, i, j, x, t, y, d, m;
  cin >> d;
  cin >> n >> m;
  vector<pair<pair<long long, long long>, pair<long long, long long>>> a(d);
  for (i = 0; i < d; i++)
    cin >> a[i].first.first >> a[i].first.second >> a[i].second.first >>
        a[i].second.second;
  long long cnt_u, cnt_d, cnt_l, cnt_r;
  cin >> cnt_u >> cnt_d >> cnt_l >> cnt_r;
  vector<long long> vl(100005, 0), vr(100005, 0), vu(100005, 0), vd(100005, 0);
  for (i = 0; i < d; i++) {
    vu[min(a[i].first.first, a[i].second.first)]++;
    vd[max(a[i].first.first, a[i].second.first)]++;
    vl[min(a[i].first.second, a[i].second.second)]++;
    vr[max(a[i].first.second, a[i].second.second)]++;
  }
  for (i = 1; i < 100005; i++) {
    vu[i] += vu[i - 1];
    vl[i] += vl[i - 1];
  }
  for (i = 100005 - 4; i >= 0; i--) {
    vd[i] += vd[i + 1];
    vr[i] += vr[i + 1];
  }
  for (i = 0; i < d; i++) {
    vu[min(a[i].first.first, a[i].second.first)]--;
    vd[max(a[i].first.first, a[i].second.first)]--;
    vl[min(a[i].first.second, a[i].second.second)]--;
    vr[max(a[i].first.second, a[i].second.second)]--;
    long long x1, x2, y1, y2;
    x1 = vu[max(a[i].first.first, a[i].second.first) - 1];
    x2 = vd[min(a[i].first.first, a[i].second.first) + 1];
    y1 = vl[max(a[i].first.second, a[i].second.second) - 1];
    y2 = vr[min(a[i].first.second, a[i].second.second) + 1];
    if (x1 == cnt_u && x2 == cnt_d && y1 == cnt_l && y2 == cnt_r) {
      cout << i + 1;
      return 0;
    }
    vu[min(a[i].first.first, a[i].second.first)]++;
    vd[max(a[i].first.first, a[i].second.first)]++;
    vl[min(a[i].first.second, a[i].second.second)]++;
    vr[max(a[i].first.second, a[i].second.second)]++;
  }
  cout << "-1";
}
