#include <bits/stdc++.h>
using namespace std;
int n, x, y;
int a[10005], b[10005], g[10005], k[10005];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i] >> g[i] >> k[i];
}
cin >> x >> y;
do
{
if (x >= a[n] && x <= g[n] && y >= b[n] && y <= k[n])
{
cout << n;
return 0;
}
}while (n--);
cout << -1;
return 0;
}