#include <bits/stdc++.h>
using namespace std;
struct s {
  int x[2];
  int y[2];
  int cnt[4];
};
int res[4];
int cntl[100005];
int cntr[100005];
int cntt[100005];
int cntb[100005];
s sofa[100005];
int main() {
  int d, n, m;
  cin >> d >> n >> m;
  for (int i = 0; i < d; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    sofa[i].x[0] = min(a, c);
    sofa[i].x[1] = max(a, c);
    sofa[i].y[0] = min(b, d);
    sofa[i].y[1] = max(b, d);
    cntl[sofa[i].x[0]]++;
    cntt[sofa[i].y[0]]++;
    cntr[sofa[i].x[1]]++;
    cntb[sofa[i].y[1]]++;
  }
  cin >> res[0] >> res[1] >> res[2] >> res[3];
  for (int i = 1; i <= n; i++) cntl[i] += cntl[i - 1];
  for (int i = 1; i <= m; i++) cntt[i] += cntt[i - 1];
  for (int i = n; i >= 1; i--) cntr[i - 1] += cntr[i];
  for (int i = m; i >= 1; i--) cntb[i - 1] += cntb[i];
  for (int i = 0; i < d; i++) {
    sofa[i].cnt[0] = cntl[sofa[i].x[1] - 1];
    sofa[i].cnt[1] = cntr[sofa[i].x[0] + 1];
    sofa[i].cnt[2] = cntt[sofa[i].y[1] - 1];
    sofa[i].cnt[3] = cntb[sofa[i].y[0] + 1];
    if (sofa[i].x[0] != sofa[i].x[1]) {
      sofa[i].cnt[0]--;
      sofa[i].cnt[1]--;
    }
    if (sofa[i].y[0] != sofa[i].y[1]) {
      sofa[i].cnt[2]--;
      sofa[i].cnt[3]--;
    }
  }
  for (int i = 0; i < d; i++) {
    if (sofa[i].cnt[0] == res[0] && sofa[i].cnt[1] == res[1] &&
        sofa[i].cnt[2] == res[2] && sofa[i].cnt[3] == res[3]) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
