#include<stdio.h>
int a[11000][11000];
int s[40003];
int main(){
int x,y,t,i,m,n;
scanf("%d",&t);
for(i=1;i<=t;i++)
{scanf("%d%d%d%d",&s[4*t],&s[4*t-1],&s[4*t-2],&s[4*t-3]);
}
scanf("%d%d",&x,&y);
while(t!=0)
{
for(m=s[4*t];m<=s[4*t]+s[4*t-2];m++)
for(n=s[4*t-1];n<=s[4*t-3]+s[4*t-1];n++)
a[n][m]=1;
a[4*t][4*t-1]=1;
if(a[y][x]==1)
{printf("%d",t);
return 0;}
t--;
}
printf("%d",-1);
}