#include <bits/stdc++.h>
using namespace std;
int L[100004], R[100004], U[100004], D[100004];
int n, m, d;
vector<int> dx[100004];
vector<int> dy[100004];
bool f[100004];
int main() {
  ios::sync_with_stdio(false);
  scanf("%d", &d);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= d; i++) {
    int x, y, u, v;
    scanf("%d%d%d%d", &x, &y, &u, &v);
    dx[x].push_back(i);
    if (x != u) dx[u].push_back(i);
    dy[y].push_back(i);
    if (y != v) dy[v].push_back(i);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int add = 0;
    for (int j = 0; j < dx[i].size(); j++) {
      int id = dx[i][j];
      L[id] = max(L[id], cnt - f[id]);
    }
    for (int j = 0; j < dx[i].size(); j++)
      if (f[dx[i][j]] == false) {
        f[dx[i][j]] = true;
        cnt++;
      }
  }
  cnt = 0;
  memset(f, false, sizeof(f));
  for (int i = n; i >= 1; i--) {
    int add = 0;
    for (int j = 0; j < dx[i].size(); j++) {
      int id = dx[i][j];
      R[id] = max(R[id], cnt - f[id]);
    }
    for (int j = 0; j < dx[i].size(); j++)
      if (f[dx[i][j]] == false) {
        f[dx[i][j]] = true;
        cnt++;
      }
  }
  memset(f, 0, sizeof(f));
  cnt = 0;
  for (int i = 1; i <= m; i++) {
    int add = 0;
    for (int j = 0; j < dy[i].size(); j++) {
      int id = dy[i][j];
      U[id] = max(U[id], cnt - f[id]);
    }
    for (int j = 0; j < dy[i].size(); j++)
      if (f[dy[i][j]] == false) {
        f[dy[i][j]] = true;
        cnt++;
      }
  }
  cnt = 0;
  memset(f, false, sizeof(f));
  for (int i = m; i >= 1; i--) {
    int add = 0;
    for (int j = 0; j < dy[i].size(); j++) {
      int id = dy[i][j];
      D[id] = max(D[id], cnt - f[id]);
    }
    for (int j = 0; j < dy[i].size(); j++)
      if (f[dy[i][j]] == false) {
        f[dy[i][j]] = true;
        cnt++;
      }
  }
  int up, dn, l, r;
  scanf("%d%d%d%d", &l, &r, &up, &dn);
  for (int i = 1; i <= d; i++) {
    if (l == L[i] && r == R[i] && up == U[i] && dn == D[i]) {
      printf("%d", i);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
