#include <bits/stdc++.h>
using namespace std;
int row1[100005], col1[100005];
int row2[100005], col2[100005];
int X1[100005], X2[100005], Y1[100005], Y2[100005];
int main() {
  int d;
  scanf("%d", &d);
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < d; i++) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    X1[i] = x1;
    X2[i] = x2;
    Y1[i] = y1;
    Y2[i] = y2;
    if (x2 < x1) swap(x1, x2);
    row1[x1]++;
    row2[x2]++;
    if (y2 < y1) swap(y1, y2);
    col1[y1]++;
    col2[y2]++;
  }
  for (int i = 2; i <= n; i++) row1[i] += row1[i - 1];
  for (int i = n - 1; i >= 1; i--) row2[i] += row2[i + 1];
  for (int i = 2; i <= m; i++) col1[i] += col1[i - 1];
  for (int i = m - 1; i >= 1; i--) col2[i] += col2[i + 1];
  int l, r, t, b;
  scanf("%d %d %d %d", &l, &r, &t, &b);
  int cnt = 0;
  for (int i = 0; i < d; i++) {
    int x1 = X1[i];
    int y1 = Y1[i];
    int x2 = X2[i];
    int y2 = Y2[i];
    int xmin = min(x1, x2);
    int xmax = max(x1, x2);
    int ymin = min(y1, y2);
    int ymax = max(y1, y2);
    int ok = 1;
    if (xmin == xmax) {
      ok &= (row1[xmin - 1] == l && row2[xmin + 1] == r);
    } else {
      ok &= (row1[xmax - 1] == l + 1 && row2[xmin + 1] == r + 1);
    }
    if (ymin == ymax) {
      ok &= (col1[ymin - 1] == t && col2[ymin + 1] == b);
    } else {
      ok &= (col1[ymax - 1] == t + 1 && col2[ymin + 1] == b + 1);
    }
    if (ok) {
      printf("%d", i + 1);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
