#include <bits/stdc++.h>
using namespace std;
long long INF = pow(10, 15);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long d;
  cin >> d;
  long long n, m;
  cin >> n >> m;
  vector<long long> v1, v2, v11, v22;
  vector<pair<long long, long long>> vx;
  vector<pair<long long, long long>> vy;
  for (int i = 0; i < d; i++) {
    long long x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x1 < x2) {
      vx.push_back({x1, x2});
      v1.push_back(x1);
      v11.push_back(x2);
    } else {
      vx.push_back({x2, x1});
      v1.push_back(x2);
      v11.push_back(x1);
    }
    if (y1 < y2) {
      vy.push_back({y1, y2});
      v2.push_back(y1);
      v22.push_back(y2);
    } else {
      vy.push_back({y2, y1});
      v2.push_back(y2);
      v22.push_back(y1);
    }
  }
  long long l, r, t, dn;
  cin >> l >> r >> t >> dn;
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  sort(v11.begin(), v11.end());
  sort(v22.begin(), v22.end());
  long long ans = -1;
  for (long long i = 0; i < d; i++) {
    long long cntl, cntr, cntt, cntd;
    long long index =
        lower_bound(v1.begin(), v1.end(), vx[i].second) - v1.begin();
    if (vx[i].first != vx[i].second)
      cntl = index - 1;
    else
      cntl = index;
    index = upper_bound(v11.begin(), v11.end(), vx[i].first) - v11.begin();
    if (vx[i].first != vx[i].second)
      cntr = d - index - 1;
    else
      cntr = d - index;
    index = lower_bound(v2.begin(), v2.end(), vy[i].second) - v2.begin();
    if (vy[i].second != vy[i].first)
      cntt = index - 1;
    else
      cntt = index;
    index = upper_bound(v22.begin(), v22.end(), vy[i].first) - v22.begin();
    if (vy[i].first != vy[i].second)
      cntd = d - index - 1;
    else
      cntd = d - index;
    if (cntl == l && cntr == r && cntt == t && cntd == dn) {
      ans = i + 1;
    }
  }
  cout << ans << endl;
}
