#include <bits/stdc++.h>
using namespace std;
int d, n, m;
int coord_x1[100007], coord_y1[100007], coord_x2[100007], coord_y2[100007];
int cnt_l, cnt_r, cnt_t, cnt_b;
int Bl[100007], Br[100007], Bt[100007], Bb[100007];
int main(int argc, char *argv[]) {
  cin >> d;
  {
    cin >> n >> m;
    for (int i = 0; i < d; i++) {
      cin >> coord_x1[i] >> coord_y1[i] >> coord_x2[i] >> coord_y2[i];
      if (coord_x1[i] > coord_x2[i]) swap(coord_x1[i], coord_x2[i]);
      if (coord_y1[i] > coord_y2[i]) swap(coord_y1[i], coord_y2[i]);
    }
    cin >> cnt_l >> cnt_r >> cnt_t >> cnt_b;
    for (int i = 0; i < d; i++) {
      Bl[coord_x1[i]]++;
      Br[coord_x2[i]]++;
      Bt[coord_y1[i]]++;
      Bb[coord_y2[i]]++;
    }
    for (int i = 1; i < 100007; i++) {
      Bl[i] += Bl[i - 1];
      Bt[i] += Bt[i - 1];
    }
    for (int i = 100007 - 2; i >= 0; i--) {
      Br[i] += Br[i + 1];
      Bb[i] += Bb[i + 1];
    }
    int r = 0;
    for (int i = 0; i < d; i++) {
      int my_l = Bl[coord_x2[i] - 1];
      if (coord_x2[i] != coord_x1[i]) my_l--;
      int my_r = Br[coord_x1[i] + 1];
      if (coord_x2[i] != coord_x1[i]) my_r--;
      int my_t = Bt[coord_y2[i] - 1];
      if (coord_y2[i] != coord_y1[i]) my_t--;
      int my_b = Bb[coord_y1[i] + 1];
      if (coord_y2[i] != coord_y1[i]) my_b--;
      if (my_l == cnt_l && my_r == cnt_r && my_t == cnt_t && my_b == cnt_b) {
        r = i + 1;
        break;
      }
    }
    if (r == 0) r = -1;
    printf("%d\n", r);
  }
}
