#include <bits/stdc++.h>
using namespace std;
void solve(int d, int n, vector<int> X[], int right[], int left[]) {
  int i, j, done = 0, start = 0, counter[d], counter2[d], precounter[d];
  for (i = 0; i < d; i++) {
    counter[i] = counter2[i] = precounter[i] = 0;
  }
  for (i = 1; i <= n; i++) {
    int now = 0;
    for (j = 0; j < X[i].size(); j++) {
      counter[X[i][j]]++;
      if (counter[X[i][j]] == 2) {
        done++;
      } else {
        now++;
      }
    }
    for (j = 0; j < X[i].size(); j++) {
      counter2[X[i][j]]++;
      if (counter2[X[i][j]] == 1) {
        right[X[i][j]] = d - done;
        if (counter[X[i][j]] == 1) {
          right[X[i][j]]--;
        }
      } else {
        left[X[i][j]] = start - 1;
        if (precounter[X[i][j]] == 0) {
          left[X[i][j]]++;
        }
      }
    }
    for (j = 0; j < X[i].size(); j++) {
      precounter[X[i][j]] += 1;
    }
    start += now;
  }
}
int main() {
  int d, n, m, x1, x2, y1, y2, i;
  cin >> d;
  cin >> n >> m;
  vector<int> X[n + 1], Y[m + 1];
  for (i = 0; i < d; i++) {
    cin >> x1 >> y1 >> x2 >> y2;
    X[x1].push_back(i);
    X[x2].push_back(i);
    Y[y1].push_back(i);
    Y[y2].push_back(i);
  }
  int left[d], right[d], top[d], down[d];
  solve(d, n, X, right, left);
  solve(d, m, Y, down, top);
  cin >> x1 >> x2 >> y1 >> y2;
  for (i = 0; i < d; i++) {
    if (left[i] == x1 && right[i] == x2 && top[i] == y1 && down[i] == y2) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
