#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Check {
  T begin, end;
  int before;
};
template <typename T>
void doCheck(const Check<T>& check, vector<int>& possible) {
  set<int> passed, valid;
  for (auto it = check.begin; it != check.end; ++it) {
    const auto& v = *it;
    if (!v.empty()) {
      set<int> addPassed;
      for (int sofa : v) {
        if ((passed.size() == check.before && addPassed.count(sofa) == 1) ||
            (passed.size() == check.before + 1 && passed.count(sofa) == 1))
          valid.insert(sofa);
        addPassed.insert(sofa);
      }
      passed.insert(addPassed.begin(), addPassed.end());
    }
  }
  vector<int> nextPossible;
  set_intersection(possible.begin(), possible.end(), valid.begin(), valid.end(),
                   inserter(nextPossible, nextPossible.end()));
  possible.swap(nextPossible);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int d;
  cin >> d;
  cin.ignore();
  int n, m;
  cin >> n >> m;
  cin.ignore();
  vector<vector<int>> sofaX(n + 1), sofaY(m + 1);
  vector<int> possible;
  possible.reserve(d);
  for (int i = 1; i <= d; ++i) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cin.ignore();
    sofaX[x1].push_back(i);
    sofaX[x2].push_back(i);
    sofaY[y1].push_back(i);
    sofaY[y2].push_back(i);
    possible.push_back(i);
  }
  Check<vector<vector<int>>::const_iterator> checkLeft, checkUp;
  checkLeft.begin = sofaX.begin();
  checkLeft.end = sofaX.end();
  checkUp.begin = sofaY.begin();
  checkUp.end = sofaY.end();
  Check<vector<vector<int>>::const_reverse_iterator> checkRight, checkDown;
  checkRight.begin = sofaX.rbegin();
  checkRight.end = sofaX.rend();
  checkDown.begin = sofaY.rbegin();
  checkDown.end = sofaY.rend();
  cin >> checkLeft.before >> checkRight.before >> checkUp.before >>
      checkDown.before;
  cin.ignore();
  doCheck(checkLeft, possible);
  doCheck(checkUp, possible);
  doCheck(checkRight, possible);
  doCheck(checkDown, possible);
  if (possible.empty())
    cout << "-1" << endl;
  else if (possible.size() == 1)
    cout << *possible.begin() << endl;
  else
    exit(1);
  return 0;
}
