#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int t, n, m, k, r, c, x, y, w;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> r >> c;
  int a[n], b[n], c[n], d[n];
  int ia[n], ib[n], ic[n], id[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    if (c[i] < a[i]) swap(a[i], c[i]);
    if (d[i] < b[i]) swap(d[i], b[i]);
    ia[i] = a[i];
    ib[i] = b[i];
    ic[i] = c[i];
    id[i] = d[i];
  }
  sort(ia, ia + n);
  sort(ib, ib + n);
  sort(ic, ic + n);
  sort(id, id + n);
  int c1[n], c2[n], c3[n], c4[n];
  int t1, t2, t3, t4;
  cin >> t1 >> t2 >> t3 >> t4;
  for (int i = 0; i < n; ++i) {
    c1[i] = lower_bound(ia, ia + n, c[i]) - ia;
    c2[i] = ic + n - upper_bound(ic, ic + n, a[i]);
    if (a[i] < c[i]) c1[i]--, c2[i]--;
    c3[i] = lower_bound(ib, ib + n, d[i]) - ib;
    c4[i] = id + n - upper_bound(id, id + n, b[i]);
    if (b[i] < d[i]) c3[i]--, c4[i]--;
    if (c1[i] == t1 and c2[i] == t2 and c3[i] == t3 and c4[i] == t4) {
      cout << i + 1 << '\n';
      exit(0);
    }
  }
  cout << -1 << '\n';
  return 0;
}
