#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a, b;
int ans1[N], ans2[N], ans3[N], ans4[N];
vector<int> A[N], B[N];
bool vis1[N], vis2[N], vis3[N], vis4[N];
int main() {
  scanf("%d", &n);
  scanf("%d %d", &a, &b);
  for (int i = 0; i < n; ++i) {
    int x_1, y_1, x_2, y_2;
    scanf("%d %d %d %d", &x_1, &y_1, &x_2, &y_2);
    A[x_1].push_back(i);
    A[x_2].push_back(i);
    B[y_1].push_back(i);
    B[y_2].push_back(i);
  }
  int cnt = 0;
  for (int i = 1; i <= a; ++i) {
    int in = 0;
    for (int j = 0; j < A[i].size(); ++j) {
      int v = A[i][j];
      ans1[v] = max(ans1[v], cnt - vis1[v]);
      if (not vis1[v]) in += 1;
      vis1[v] = 1;
    }
    cnt += in;
  }
  cnt = 0;
  for (int i = a; i >= 1; --i) {
    int in = 0;
    for (int j = 0; j < A[i].size(); ++j) {
      int v = A[i][j];
      ans2[v] = max(ans2[v], cnt - vis2[v]);
      if (not vis2[v]) in += 1;
      vis2[v] = 1;
    }
    cnt += in;
  }
  cnt = 0;
  for (int i = 1; i <= b; ++i) {
    int in = 0;
    for (int j = 0; j < B[i].size(); ++j) {
      int v = B[i][j];
      ans3[v] = max(ans3[v], cnt - vis3[v]);
      if (not vis3[v]) in += 1;
      vis3[v] = 1;
    }
    cnt += in;
  }
  cnt = 0;
  for (int i = b; i >= 1; --i) {
    int in = 0;
    for (int j = 0; j < B[i].size(); ++j) {
      int v = B[i][j];
      ans4[v] = max(ans4[v], cnt - vis4[v]);
      if (not vis4[v]) in += 1;
      vis4[v] = 1;
    }
    cnt += in;
  }
  int x, y, z, w;
  scanf("%d %d %d %d", &x, &y, &z, &w);
  int res = -1;
  for (int i = 0; i < n; ++i) {
    if (ans1[i] == x and ans2[i] == y and ans3[i] == z and ans4[i] == w)
      res = i + 1;
    ;
  }
  printf("%d\n", res);
  return 0;
}
