#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
const long long int INF = 1e10;
vector<pair<pair<int, int>, pair<int, int> > > vp;
int hor[100003], ver[100003];
int xpos[100003], ypos[100003];
int type[100003];
void build(pair<int, int> A, pair<int, int> B) {
  if (A.first == B.first)
    xpos[A.first]++, ver[A.second]++;
  else
    hor[A.first]++, ypos[A.second]++;
  return;
}
int main() {
  int i, a, b, x, y, z;
  scanf("%d", &z);
  vp.resize(z);
  scanf("%d%d", &a, &b);
  vector<pair<int, int> > temp(2);
  for (i = 0; i < z; i++) {
    scanf("%d%d", &a, &b);
    scanf("%d%d", &x, &y);
    temp[0] = {a, b};
    temp[1] = {x, y};
    sort(temp.begin(), temp.end());
    vp[i] = {temp[0], temp[1]};
    build(temp[0], temp[1]);
  }
  for (i = 1; i < 100003; i++) {
    hor[i] += hor[i - 1];
    ver[i] += ver[i - 1];
    xpos[i] += xpos[i - 1];
    ypos[i] += ypos[i - 1];
  }
  int l, r, t, d, tl, tr, tt, td;
  cin >> l >> r >> t >> d;
  int ans = -1;
  for (i = 0; i < z; i++) {
    x = vp[i].first.first, y = vp[i].first.second;
    if (vp[i].first.first == vp[i].second.first) {
      tl = xpos[x - 1] + hor[x - 1];
      tr = (xpos[100003 - 1] - xpos[x]) + (hor[100003 - 1] - hor[x - 1]);
      tt = ypos[y] + ver[y] - 1;
      td = (ypos[100003 - 1] - ypos[y]) + (ver[100003 - 1] - ver[y - 1]) - 1;
    } else {
      tl = xpos[x] + hor[x] - 1;
      tr = (xpos[100003 - 1] - xpos[x]) + (hor[100003 - 1] - hor[x - 1]) - 1;
      tt = ypos[y - 1] + ver[y - 1];
      td = (ypos[100003 - 1] - ypos[y]) + (ver[100003 - 1] - ver[y - 1]);
    }
    if (tl == l && tr == r && tt == t && td == d) ans = i + 1;
  }
  printf("%d\n", ans);
}
