#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 1e5 + 5;
int d, n, m;
int l, r, t, b;
int ll[N], rr[N], tt[N], bb[N];
int vert[N], hori[N];
int xa, ya, xb, yb;
set<int> x[N], y[N];
vector<pair<pair<int, int>, pair<int, int> > > sofas;
int main() {
  scanf("%d%d%d", &d, &n, &m);
  for (int i = 0; i < d; i++) {
    scanf("%d%d%d%d", &xa, &ya, &xb, &yb);
    x[xa].insert(i);
    x[xb].insert(i);
    y[ya].insert(i);
    y[yb].insert(i);
    sofas.push_back(make_pair(make_pair(xa, xb), make_pair(ya, yb)));
    if (xa == xb) vert[i] = 1;
    if (ya == yb) hori[i] = 1;
  }
  set<int> sumx, sumy;
  for (int i = 0; i <= N - 2; i++) {
    for (auto k : x[i]) sumx.insert(k);
    for (auto k : y[i]) sumy.insert(k);
    ll[i + 1] = sumx.size();
    tt[i + 1] = sumy.size();
  }
  sumx.clear();
  sumy.clear();
  for (int i = N - 1; i > 0; i--) {
    for (auto k : x[i]) sumx.insert(k);
    for (auto k : y[i]) sumy.insert(k);
    rr[i - 1] = sumx.size();
    bb[i - 1] = sumy.size();
  }
  scanf("%d%d%d%d", &l, &r, &t, &b);
  for (int i = 0; i < d; i++) {
    pair<int, int> xx = sofas[i].first;
    pair<int, int> yy = sofas[i].second;
    int ok = 1;
    if (ll[max(xx.first, xx.second)] - hori[i] != l) ok = 0;
    if (rr[min(xx.first, xx.second)] - hori[i] != r) ok = 0;
    if (tt[max(yy.first, yy.second)] - vert[i] != t) ok = 0;
    if (bb[min(yy.first, yy.second)] - vert[i] != b) ok = 0;
    if (ok) return 0 * printf("%d\n", i + 1);
  }
  printf("-1\n");
  return 0;
}
