#include <iostream>
using namespace std;
int main(){
int a,b[50],c[50],d[50],e[50];
int z[20][20];
for(int i=0;i<20;i++){for(int t=0;t<20;t++){z[i][t]=-1;}}
cin>>a;
for(int i=1;i<=a;i++){
cin>>b[i]>>c[i]>>d[i]>>e[i];
for(int t=b[i];t<=b[i]+d[i];t++){
for(int p=c[i];p<=c[i]+e[i];p++){
z[t][p]=i;
}
}
}
int w,r;
cin>>w>>r;
cout<<z[w][r]<<endl;
return 0;
}```