#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int x1[N], x2[N], y11[N], y2[N], bottom[N], top[N], esq[N], dir[N];
vector<int> comecoy, comecox, fimx, fimy;
int main(void) {
  int d;
  scanf("%d", &d);
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < d; i++) {
    scanf("%d %d %d %d", x1 + i, y11 + i, x2 + i, y2 + i);
    if (x1[i] > x2[i]) swap(x1[i], x2[i]);
    if (y11[i] > y2[i]) swap(y11[i], y2[i]);
    comecoy.push_back(y11[i]);
    comecox.push_back(x1[i]);
    fimx.push_back(x2[i]);
    fimy.push_back(y2[i]);
  }
  sort(comecoy.begin(), comecoy.end());
  sort(fimy.begin(), fimy.end());
  for (int i = 0; i < d; i++) {
    int k = upper_bound(comecoy.begin(), comecoy.end(), y2[i] - 1) -
            comecoy.begin();
    top[i] += k + (y11[i] < y2[i] ? -1 : 0);
    k = upper_bound(fimy.begin(), fimy.end(), y11[i]) - fimy.begin();
    k = d - k + (y11[i] == y2[i] ? 0 : -1);
    bottom[i] += k;
  }
  sort(comecox.begin(), comecox.end());
  sort(fimx.begin(), fimx.end());
  for (int i = 0; i < d; i++) {
    int k = upper_bound(comecox.begin(), comecox.end(), x2[i] - 1) -
            comecox.begin();
    esq[i] += k + (x1[i] < x2[i] ? -1 : 0);
    k = upper_bound(fimx.begin(), fimx.end(), x1[i]) - fimx.begin();
    k = d - k + (x1[i] == x2[i] ? 0 : -1);
    dir[i] += k;
  }
  int a, b, c, e;
  cin >> a >> b >> c >> e;
  for (int i = 0; i < d; i++) {
    if (a == esq[i] and b == dir[i] and c == top[i] and e == bottom[i]) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
