#include <bits/stdc++.h>
using namespace std;
const int sz = 100005;
int xl[sz], xr[sz], yl[sz], yr[sz];
int xls[sz], xrs[sz], yls[sz], yrs[sz];
int main() {
  int d, n, m;
  scanf("%d%d%d", &d, &n, &m);
  int cl, cr, cu, cd;
  for (int i = 0; i < d; i++) {
    scanf("%d%d%d%d", xl + i, yl + i, xr + i, yr + i);
    if (xl[i] > xr[i]) swap(xl[i], xr[i]);
    if (yl[i] > yr[i]) swap(yl[i], yr[i]);
    xls[xl[i] + 1]++;
    xrs[xr[i] - 1]++;
    yls[yl[i] + 1]++;
    yrs[yr[i] - 1]++;
  }
  scanf("%d%d%d%d", &cl, &cr, &cu, &cd);
  for (int i = 1; i <= n; i++) xls[i] += xls[i - 1];
  for (int i = n; i; i--) xrs[i] += xrs[i + 1];
  for (int i = 1; i <= m; i++) yls[i] += yls[i - 1];
  for (int i = m; i; i--) yrs[i] += yrs[i + 1];
  int ans = -1;
  for (int i = 0; i < d; i++) {
    int tmp;
    tmp = xls[xr[i]];
    if (xr[i] != xl[i]) tmp--;
    if (tmp != cl) continue;
    tmp = xrs[xl[i]];
    if (xr[i] != xl[i]) tmp--;
    if (tmp != cr) continue;
    tmp = yls[yr[i]];
    if (yr[i] != yl[i]) tmp--;
    if (tmp != cu) continue;
    tmp = yrs[yl[i]];
    if (yr[i] != yl[i]) tmp--;
    if (tmp != cd) continue;
    ans = i + 1;
    break;
  }
  printf("%d\n", ans);
}
