#include <bits/stdc++.h>
using namespace std;
struct Sofa {
  int x1, x2, y1, y2;
};
int n, m, d;
int righth[100001] = {0}, down[100001] = {0};
int lefth[100010] = {0}, top[100010] = {0};
Sofa sofas[100010];
void add_top(int idx, int num) {
  while (idx <= m) {
    top[idx] += num;
    idx += (idx & (-idx));
  }
}
void add_left(int idx, int num) {
  while (idx <= n) {
    lefth[idx] += num;
    idx += (idx & (-idx));
  }
}
void add_down(int idx, int num) {
  idx = m - idx + 1;
  while (idx <= m) {
    down[idx] += num;
    idx += (idx & (-idx));
  }
}
void add_right(int idx, int num) {
  idx = n - idx + 1;
  while (idx <= n) {
    righth[idx] += num;
    idx += (idx & (-idx));
  }
}
int sum_top(int idx) {
  int res = 0;
  while (idx > 0) {
    res += top[idx];
    idx -= (idx & (-idx));
  }
  return res;
}
int sum_left(int idx) {
  int res = 0;
  while (idx > 0) {
    res += lefth[idx];
    idx -= (idx & (-idx));
  }
  return res;
}
int sum_right(int idx) {
  int res = 0;
  idx = n - idx + 1;
  while (idx > 0) {
    res += righth[idx];
    idx -= (idx & (-idx));
  }
  return res;
}
int sum_down(int idx) {
  int res = 0;
  idx = m - idx + 1;
  while (idx > 0) {
    res += down[idx];
    idx -= (idx & (-idx));
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> d >> n >> m;
  for (int i = 1; i <= d; i++) {
    cin >> sofas[i].x1 >> sofas[i].y1 >> sofas[i].x2 >> sofas[i].y2;
    int minx = min(sofas[i].x1, sofas[i].x2);
    int miny = min(sofas[i].y1, sofas[i].y2);
    int maxx = max(sofas[i].x2, sofas[i].x1);
    int maxy = max(sofas[i].y2, sofas[i].y1);
    add_top(miny, 1);
    add_left(minx, 1);
    add_down(maxy, 1);
    add_right(maxx, 1);
  }
  int cl, cr, ct, cd;
  cin >> cl >> cr >> ct >> cd;
  for (int i = 1; i <= d; i++) {
    int minx = min(sofas[i].x1, sofas[i].x2);
    int miny = min(sofas[i].y1, sofas[i].y2);
    int maxx = max(sofas[i].x2, sofas[i].x1);
    int maxy = max(sofas[i].y2, sofas[i].y1);
    int sl, sr, st, sd;
    if (sofas[i].x1 != sofas[i].x2) {
      sl = sum_left(maxx - 1) - 1;
      sr = sum_right(minx + 1) - 1;
    } else {
      sl = sum_left(maxx - 1);
      sr = sum_right(minx + 1);
    }
    if (sofas[i].y2 != sofas[i].y1) {
      st = sum_top(maxy - 1) - 1;
      sd = sum_down(miny + 1) - 1;
    } else {
      st = sum_top(maxy - 1);
      sd = sum_down(miny + 1);
    }
    if (sl == cl && sr == cr && st == ct && sd == cd) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
