#include <bits/stdc++.h>
using namespace std;
struct sofatype {
  int x1, y1;
  int x2, y2;
};
const int maxn = 100010;
sofatype sofa[maxn];
int cnt_left[maxn], cnt_right[maxn], cnt_top[maxn], cnt_bottom[maxn];
int main() {
  int d;
  int n, m;
  scanf("%d", &d);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= d; i++)
    scanf("%d%d%d%d", &sofa[i].x1, &sofa[i].y1, &sofa[i].x2, &sofa[i].y2);
  for (int i = 1; i <= d; i++) cnt_left[min(sofa[i].x1, sofa[i].x2)]++;
  for (int i = 2; i < maxn; i++) cnt_left[i] += cnt_left[i - 1];
  for (int i = 1; i <= d; i++) cnt_right[max(sofa[i].x1, sofa[i].x2)]++;
  for (int i = maxn - 2; i >= 1; i--) cnt_right[i] += cnt_right[i + 1];
  for (int i = 1; i <= d; i++) cnt_top[min(sofa[i].y1, sofa[i].y2)]++;
  for (int i = 2; i < maxn; i++) cnt_top[i] += cnt_top[i - 1];
  for (int i = 1; i <= d; i++) cnt_bottom[max(sofa[i].y1, sofa[i].y2)]++;
  for (int i = maxn - 2; i >= 1; i--) cnt_bottom[i] += cnt_bottom[i + 1];
  int l, r, t, b;
  scanf("%d%d%d%d", &l, &r, &t, &b);
  for (int i = 1; i <= d; i++) {
    int left = (sofa[i].x1 == sofa[i].x2)
                   ? cnt_left[sofa[i].x1 - 1]
                   : cnt_left[max(sofa[i].x1, sofa[i].x2) - 1] - 1;
    int right = (sofa[i].x1 == sofa[i].x2)
                    ? cnt_right[sofa[i].x1 + 1]
                    : cnt_right[min(sofa[i].x1, sofa[i].x2) + 1] - 1;
    int top = (sofa[i].x1 == sofa[i].x2)
                  ? cnt_top[max(sofa[i].y1, sofa[i].y2) - 1] - 1
                  : cnt_top[sofa[i].y1 - 1];
    int bottom = (sofa[i].x1 == sofa[i].x2)
                     ? cnt_bottom[min(sofa[i].y1, sofa[i].y2) + 1] - 1
                     : cnt_bottom[sofa[i].y1 + 1];
    if (left == l && right == r && top == t && bottom == b) {
      printf("%d\n", i);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
