#include <bits/stdc++.h>
using namespace std;
int n,g[10001][10001],a,b,x,y;
void fun(int q,int a,int b,int x,int y)
{
g[a][b]=q;
for(int m=1;m<=x;m++)
for(int l=1;l<=y;l++)
g[m][l]=q;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a>>b>>x>>y;
fun(i,a,b,x,y);
}
cin>>x>>y;
if(g[x][y]!=0) cout<<g[x][y]<<endl;
else cout<<"-1"<<endl;
return 0;
}