#include <bits/stdc++.h>
using namespace std;
struct sofa {
  int x1, y1, x2, y2;
  int ver, hor;
  sofa(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {
    ver = hor = 0;
    if (x1 == x2) ver = 1;
    if (y1 == y2) hor = 1;
  }
};
int d, n, m;
int l, r, t, b;
vector<sofa> sofas;
vector<int> upsofas, downsofas, rightsofas, leftsofas;
int main() {
  cin >> d >> n >> m;
  for (int i = 0; i < d; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    sofas.push_back(sofa(x1, y1, x2, y2));
    upsofas.push_back(max(y1, y2));
    downsofas.push_back(min(y1, y2));
    rightsofas.push_back(max(x1, x2));
    leftsofas.push_back(min(x1, x2));
  }
  cin >> l >> r >> b >> t;
  sort(upsofas.begin(), upsofas.end());
  sort(downsofas.begin(), downsofas.end());
  sort(rightsofas.begin(), rightsofas.end());
  sort(leftsofas.begin(), leftsofas.end());
  for (int i = 0; i < d; i++) {
    int miny = min(sofas[i].y1, sofas[i].y2),
        maxy = max(sofas[i].y1, sofas[i].y2),
        minx = min(sofas[i].x1, sofas[i].x2),
        maxx = max(sofas[i].x1, sofas[i].x2);
    int uptome = upsofas.end() -
                 upper_bound(upsofas.begin(), upsofas.end(), miny) -
                 sofas[i].ver,
        righttome = rightsofas.end() -
                    upper_bound(rightsofas.begin(), rightsofas.end(), minx) -
                    sofas[i].hor,
        downtome = lower_bound(downsofas.begin(), downsofas.end(), maxy) -
                   downsofas.begin() - sofas[i].ver,
        leftome = lower_bound(leftsofas.begin(), leftsofas.end(), maxx) -
                  leftsofas.begin() - sofas[i].hor;
    if (uptome == t && downtome == b && leftome == l && righttome == r) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
