#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans % m;
}
typedef struct sofa {
  long long x1, y1, x2, y2, id;
} nd;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long d;
  cin >> d;
  vector<nd> v(d);
  long long n, m;
  cin >> n >> m;
  long long cl, cr, cu, cd;
  vector<long long> xleft(n + 1, 0);
  vector<long long> xright(n + 1, 0);
  vector<long long> yup(m + 1, 0);
  vector<long long> ydown(m + 1, 0);
  for (long long i = 0; i < d; i++) {
    long long x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    long long minx = min(x1, x2);
    long long maxx = max(x1, x2);
    xleft[minx]++;
    xright[maxx]++;
    v[i].x1 = minx;
    v[i].x2 = maxx;
    long long miny = min(y1, y2);
    long long maxy = max(y1, y2);
    yup[miny]++;
    ydown[maxy]++;
    v[i].y1 = miny;
    v[i].y2 = maxy;
    v[i].id = i;
  }
  cin >> cl >> cr >> cu >> cd;
  for (long long i = 1; i <= n; i++) {
    xleft[i] += xleft[i - 1];
    xright[i] += xright[i - 1];
  }
  for (long long i = 1; i <= m; i++) {
    yup[i] += yup[i - 1];
    ydown[i] += ydown[i - 1];
  }
  for (long long i = 0; i < d; i++) {
    long long ctl = xleft[v[i].x2 - 1];
    if (v[i].x1 < v[i].x2) {
      ctl--;
    }
    long long ctr = d - xright[v[i].x1];
    if (v[i].x2 > v[i].x1) {
      ctr--;
    }
    long long ctu = yup[v[i].y2 - 1];
    if (v[i].y1 < v[i].y2) {
      ctu--;
    }
    long long ctd = d - ydown[v[i].y1];
    if (v[i].y2 > v[i].y1) {
      ctd--;
    }
    if (cl == ctl && cr == ctr && cu == ctu && cd == ctd) {
      cout << i + 1;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
