#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long infl = 2e18;
const long long infi = 2e9;
const long long mod = 1e9 + 7;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
auto clk = clock();
long long rng(long long lim) {
  uniform_int_distribution<long long> uid(0, lim - 1);
  return uid(rang);
}
vector<long long> top, bot, leftt, rightt;
vector<pair<pair<long long, long long>, pair<long long, long long>>> hol;
void solve() {
  long long d, n, m;
  cin >> d >> n >> m;
  for (long long i = 1; i <= d; i++) {
    long long x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    hol.push_back({{x1, y1}, {x2, y2}});
    top.push_back(min(y1, y2));
    bot.push_back(max(y1, y2));
    leftt.push_back(min(x1, x2));
    rightt.push_back(max(x1, x2));
  }
  sort(top.begin(), top.end());
  sort(bot.begin(), bot.end());
  sort(leftt.begin(), leftt.end());
  sort(rightt.begin(), rightt.end());
  long long cntl, cntr, cntt, cntb;
  cin >> cntl >> cntr >> cntt >> cntb;
  for (long long i = 0; i < hol.size(); i++) {
    auto& sofa = hol[i];
    long long up = lower_bound(top.begin(), top.end(),
                               max(sofa.first.second, sofa.second.second)) -
                   top.begin();
    long long down =
        bot.end() - upper_bound(bot.begin(), bot.end(),
                                min(sofa.first.second, sofa.second.second));
    if (sofa.first.second != sofa.second.second) up--, down--;
    long long lef = lower_bound(leftt.begin(), leftt.end(),
                                max(sofa.first.first, sofa.second.first)) -
                    leftt.begin();
    long long rig =
        rightt.end() - upper_bound(rightt.begin(), rightt.end(),
                                   min(sofa.first.first, sofa.second.first));
    if (sofa.first.first != sofa.second.first) lef--, rig--;
    ;
    if (up == cntt && down == cntb && lef == cntl && rig == cntr) {
      cout << i + 1 << '\n';
      return;
    }
  }
  cout << -1 << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  long long t = 1;
  while (t--) solve();
  return 0;
}
