#include<iostream>
#include<cstdio>
using namespace std;
struct CA
{
int a,b,c,d;
}ca[100001];
int main()
{
freopen("carpet.in","r",stdin);
freopen("carpet.out","w",stdout);
int n,a,b,c,d,q,p;
cin>>n;
for (int i=1;i<=n;i++)
cin>>ca[i].a>>ca[i].b>>ca[i].c>>ca[i].d;
cin>>q>>p;
for (int i=n;i>=1;i--)
if (ca[i].a<=q&&ca[i].a+ca[i].c>=q&&ca[i].b<=p&&ca[i].b+ca[i].d>=p)
{
cout<<i;
return 0;
}
cout<<"-1";
return 0;
}