#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct sofa {
  pair<int, int> X, Y;
  int id;
  int cntl, cntr, cntt, cntb;
} sofas[maxn];
int d, n, m;
int cntl, cntr, cntt, cntb;
bool cmp1(sofa a, sofa b) { return a.X < b.X; }
bool cmp2(sofa a, sofa b) { return a.Y < b.Y; }
bool cmp3(sofa a, sofa b) { return a.id < b.id; }
int bin_ser_x1(int l, int r, pair<int, int> x) {
  while (l <= r) {
    int mid = (l + r) / 2;
    if (sofas[mid].X >= x) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return l;
}
int bin_ser_x2(int l, int r, pair<int, int> x) {
  while (l <= r) {
    int mid = (l + r) / 2;
    if (sofas[mid].X > x) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return l;
}
int bin_ser_y1(int l, int r, pair<int, int> y) {
  while (l <= r) {
    int mid = (l + r) / 2;
    if (sofas[mid].Y >= y) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return l;
}
int bin_ser_y2(int l, int r, pair<int, int> y) {
  while (l <= r) {
    int mid = (l + r) / 2;
    if (sofas[mid].Y > y) {
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return l;
}
int main() {
  cin >> d;
  cin >> n >> m;
  for (int i = 0; i < d; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x1 > x2) swap(x1, x2);
    if (y1 > y2) swap(y1, y2);
    sofas[i].X = pair<int, int>(x1, x2);
    sofas[i].Y = pair<int, int>(y1, y2);
    sofas[i].id = i;
  }
  cin >> cntl >> cntr >> cntt >> cntb;
  sort(sofas, sofas + d, cmp1);
  for (int i = 0; i < d; i++) {
    if (sofas[i].X.first == sofas[i].X.second) {
      sofas[i].cntl = bin_ser_x1(0, d - 1, sofas[i].X);
      sofas[i].cntr = d - bin_ser_x2(0, d - 1, sofas[i].X);
    } else {
      sofas[i].cntl = bin_ser_x2(0, d - 1, sofas[i].X) - 1;
      sofas[i].cntr = d - bin_ser_x1(0, d - 1, sofas[i].X) - 1;
    }
  }
  sort(sofas, sofas + d, cmp2);
  for (int i = 0; i < d; i++) {
    if (sofas[i].Y.first == sofas[i].Y.second) {
      sofas[i].cntt = bin_ser_y1(0, d - 1, sofas[i].Y);
      sofas[i].cntb = d - bin_ser_y2(0, d - 1, sofas[i].Y);
    } else {
      sofas[i].cntt = bin_ser_y2(0, d - 1, sofas[i].Y) - 1;
      sofas[i].cntb = d - bin_ser_y1(0, d - 1, sofas[i].Y) - 1;
    }
  }
  sort(sofas, sofas + d, cmp3);
  int ans = -1;
  for (int i = 0; i < d; i++) {
    if (sofas[i].cntl == cntl && sofas[i].cntr == cntr &&
        sofas[i].cntt == cntt && sofas[i].cntb == cntb) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
