#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 1e4 + 9;
int n, a[N], b[N], g[N], k[N], x, y;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef BIG_BANANA_A_BIG_BANANA_YOUR_FEEL_VERY_WORDFUL
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i] >> b[i] >> g[i] >> k[i];
cin >> x >> y;
for (int i = n; i >= 1; i--) {
if (a[i] <= x && b[i] >= y) {
if (a[i] + g[i] >= x && b[i] + k[i] >= y) {
cout << i << endl;
exit(0);
}
}
}
cout << -1 << endl;
return 0;
}