#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>

int main(void)
{
  int d;
  int n, m;

  std::vector<std::pair<std::pair<int, int>, std::pair<int, int>>> sofas;
  std::vector<int> lefts;
  std::vector<int> rights;
  std::vector<int> tops;
  std::vector<int> bottoms;

  scanf("%d %d %d", &d, &n, &m);
  for(int i = 0; i < d; i ++)
  {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

    sofas.push_back(std::make_pair(std::make_pair(x1, y1), std::make_pair(x2, y2)));

    lefts.push_back(std::min(x1, x2));
    rights.push_back(std::max(x1, x2));
    tops.push_back(std::min(y1, y2));
    bottoms.push_back(std::max(y1, y2));
  }

  std::sort(lefts.begin(), lefts.end());
  std::sort(rights.begin(), rights.end());
  std::sort(tops.begin(), tops.end());
  std::sort(bottoms.begin(), bottoms.end());

  int gl, gr, gt, gb;
  scanf("%d %d %d %d", &gl, &gr, &gt, &gb);

  for(int i = 0; i < d; i ++)
  {
    const auto s = sofas[i];
    const int x1 = s.first.first, y1 = s.first.second, x2 = s.second.first, y2 = s.second.second;

    int l, r, t, b;

    l = (int)(std::upper_bound(lefts.begin(), lefts.end(), std::max(x1, x2) - 1) - lefts.begin()) - (x1 != x2);
    r = (int)(rights.end() - std::lower_bound(rights.begin(), rights.end(), std::min(x1, x2) + 1)) - (x1 != x2);;
    t = (int)(std::upper_bound(tops.begin(), tops.end(), std::max(y1, y2) - 1) - tops.begin()) - (y1 != y2);
    b = (int)(bottoms.end() - std::lower_bound(bottoms.begin(), bottoms.end(), std::min(y1, y2) + 1)) - (y1 != y2);

    //fprintf(stderr, "%d => %d %d %d %d\n", i, l, r, t, b);

    if(l == gl && r == gr && t == gt && b == gb)
    {
      printf("%d\n", i + 1);
      return 0;
    }
  }

  puts("-1");

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
int d,n,m;
struct cell
{
	int x,y,id;
	cell(){}
	cell(int x,int y,int id):x(x),y(y),id(id){}
};
vector<cell> cs;
bool has[100100];
int cn,cur;
bool less2(cell &a,cell &b)
{
	return a.x<b.x;
}
bool less3(cell &a,cell &b)
{
	return a.y<b.y;
}
int cnt[4][100100];
int ned[4];
int main()
{
	scanf("%d%d%d",&d,&n,&m);
	int w,x,y,z;
	for(int i=0;i<d;i++)
	{
		scanf("%d%d%d%d",&w,&x,&y,&z);
		cs.push_back(cell(w,x,i));
		cs.push_back(cell(y,z,i));
	}
	sort(cs.begin(),cs.end(),less2);
	int id;
	for(int i=0;i<cs.size();i++)
	{
		int j=i;
		while(j+1<cs.size()&&cs[j+1].x==cs[i].x)j=j+1;
		for(int k=i;k<=j;k++)
		{
			id=cs[k].id;
			cnt[0][id]=cn;
			if(has[id])cnt[0][id]--;
		}
		for(int k=i;k<=j;k++)
		{
			id=cs[k].id;
			if(!has[id])
			{
				has[id]=1;
				cn++;
			}
		}
		i=j;
	}
	memset(has,0,sizeof(has));
	cn=0;
	for(int i=cs.size()-1;i>=0;i--)
	{
		int j=i;
		while(j-1>=0&&cs[j-1].x==cs[i].x)j=j-1;
		for(int k=j;k<=i;k++)
		{
			id=cs[k].id;
			cnt[1][id]=cn;
			if(has[id])cnt[1][id]--;
		}
		for(int k=j;k<=i;k++)
		{
			id=cs[k].id;
			if(!has[id])
			{
				has[id]=1;
				cn++;
			}
		}
		i=j;
	}
	sort(cs.begin(),cs.end(),less3);
	memset(has,0,sizeof(has));
	cn=0;
	for(int i=0;i<cs.size();i++)
	{
		int j=i;
		while(j+1<cs.size()&&cs[j+1].y==cs[i].y)j=j+1;
		for(int k=i;k<=j;k++)
		{
			id=cs[k].id;
			cnt[2][id]=cn;
			if(has[id])cnt[2][id]--;
		}
		for(int k=i;k<=j;k++)
		{
			id=cs[k].id;
			if(!has[id])
			{
				has[id]=1;
				cn++;
			}
		}
		i=j;
	}
	memset(has,0,sizeof(has));
	cn=0;
	for(int i=cs.size()-1;i>=0;i--)
	{
		int j=i;
		while(j-1>=0&&cs[j-1].y==cs[i].y)j=j-1;
		for(int k=j;k<=i;k++)
		{
			id=cs[k].id;
			cnt[3][id]=cn;
			if(has[id])cnt[3][id]--;
		}
		for(int k=j;k<=i;k++)
		{
			id=cs[k].id;
			if(!has[id])
			{
				has[id]=1;
				cn++;
			}
		}
		i=j;
	}
	for(int i=0;i<4;i++)scanf("%d",&ned[i]);
	for(int i=0;i<d;i++)
	{
		bool ok=1;
		for(int j=0;j<4;j++)
			if(ned[j]!=cnt[j][i])ok=0;
		if(ok)
		{
			printf("%d\n",i+1);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}


#include <bits/stdc++.h>
#define SIZE 100005
using namespace std;
int LL[SIZE];
int RR[SIZE];
int UU[SIZE];
int DD[SIZE];
int LL_SUM[SIZE];
int RR_SUM[SIZE];
int UU_SUM[SIZE];
int DD_SUM[SIZE];

int d;
int n,m;
int cntl,cntr, cntd, cntu;
struct sofa
{
    int x1,y1,x2,y2;
    sofa(){};
    sofa(int x1, int x2, int y1, int y2):x1(x1),y1(y1),x2(x2),y2(y2){};
}S[SIZE];
int main()
{
    int ansx1,ansy1, ansx2, ansy2, x1, y1, x2, y2;
    scanf("%d", &d);
    scanf("%d%d", &n,&m);
    for(int i=1; i<=d; i++)
    {
        scanf("%d%d%d%d", &S[i].x1, &S[i].y1, &S[i].x2, &S[i].y2);
        x1=S[i].x1;
        y1=S[i].y1;
        x2=S[i].x2;
        y2=S[i].y2;
        if(x1>x2) swap(x1, x2);
        if(y1>y2) swap(y1, y2);
        LL[x1]++;
        RR[x2]++;
        DD[y1]++;
        UU[y2]++;
    }
    scanf("%d%d%d%d", &cntl, &cntr, &cntd, &cntu);
    LL_SUM[0]=0;
    RR_SUM[n+1]=0;
    UU_SUM[m+1]=0;
    DD_SUM[0]=0;
    for(int i=1; i<=n; i++)
    {
        LL_SUM[i]=LL_SUM[i-1]+LL[i];
    }
    for(int i=n; i>=1; i--)
    {
        RR_SUM[i]=RR_SUM[i+1]+RR[i];
    }
    for(int i=1; i<=m; i++)
    {
        DD_SUM[i]=DD_SUM[i-1]+DD[i];
    }
    for(int i=m; i>=1; i--)
    {
        UU_SUM[i]=UU_SUM[i+1]+UU[i];
    }
    for(int i=1; i<=d; i++)
    {
        ansx1=LL_SUM[max(S[i].x1, S[i].x2)-1];
        if(S[i].x1!=S[i].x2) ansx1--;
        ansx2=RR_SUM[min(S[i].x1, S[i].x2)+1];
        if(S[i].x1!=S[i].x2) ansx2--;
        ansy1=DD_SUM[max(S[i].y1, S[i].y2)-1];
        if(S[i].y1!=S[i].y2) ansy1--;
        ansy2=UU_SUM[min(S[i].y1, S[i].y2)+1];
        if(S[i].y1!=S[i].y2) ansy2--;

        if(ansx1==cntl&&ansx2==cntr&&ansy1==cntd&&ansy2==cntu)
        {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, A;
int c[1000005];
int cnt[1000005];
bool ret[1000005];
int main()
{
    scanf("%d%d", &n, &A);
    for(int i=1; i<=n; i++)
    {
        scanf("%d", &c[i]);
    }
    for(int i=1; i<=1000000; i++)
        ret[i]=1;
    memset(cnt, 0, sizeof cnt);
    for(int i=1; i<=n; i++)
    {
        if(c[i]==A)
        {
            cnt[A]++;
        }
        else{
                if(ret[c[i]])
                {
                    if(cnt[c[i]]>=cnt[A])
                    {
                        cnt[c[i]]++;
                    }
                    else{
                        ret[c[i]]=0;
                    }
                }
        }
    }
    int ans=-1;
    for(int i=1; i<=1000000; i++)
    {
        if(i!=A&&ret[i]&&cnt[i]>=cnt[A])
        {
            ans=i;
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fill(A,B) memset(A,B,sizeof(A))
#define For(i,A,B) for(int i=(A);i<(int)(B);i++)
#define rep(i,A,B) for(int i=(A);i<=(B);i++)
#define dep(i,B,A) for(int i=(B);i>=(A);i--)
#define re(i,A) for(int i=0;i<(int)(A);i++)
#define de(i,A) for(int i=(A)-1;~i;i--)
#define inf (1<<30)
#define mn 111
#define M 100000000003ll
#define si(x) ((int)x.size())
#define MAX(A,B) A=max(A,B)
#define MIN(A,B) A=min(A,B)
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
template<class T>inline void R(T &xx){xx=0;char ch=getchar();bool F=0;while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if(ch=='-')F=1,ch=getchar();while(ch>='0'&&ch<='9')xx=xx+xx+(xx<<3)+ch-48,ch=getchar();if(F)xx=-xx;}

int d,n,m,X1[mn],X2[mn],Y1[mn],Y2[mn];
vector<int>x1,x2,y1,y2;
int le[mn],tp[mn],bo[mn],ri[mn],l,r,t,b;
int main(){
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    //freopen("2.out","w",stdout);
#endif
	R(d);
	R(n),R(m);
	re(i,d){
		R(X1[i]),R(Y1[i]),R(X2[i]),R(Y2[i]);
		if(X1[i]>X2[i])swap(X1[i],X2[i]);
		if(Y1[i]>Y2[i])swap(Y1[i],Y2[i]);

		x1.pb(X1[i]);
		y1.pb(Y1[i]);
		x2.pb(X2[i]);
		y2.pb(Y2[i]);
	}
	R(l),R(r),R(t),R(b);
	#define all(x) x.begin(),x.end()
	sort(all(x1));sort(all(x2));sort(all(y1));sort(all(y2));
	re(i,d){
		le[i]=lower_bound(all(x1),X2[i])-x1.begin()-(X1[i]!=X2[i]);
		tp[i]=lower_bound(all(y1),Y2[i])-y1.begin()-(Y1[i]!=Y2[i]);
		ri[i]=d-(upper_bound(all(x2),X1[i])-x2.begin())-(X1[i]!=X2[i]);
		bo[i]=d-(upper_bound(all(y2),Y1[i])-y2.begin())-(Y1[i]!=Y2[i]);
	//	printf("%d %d %d %d\n",le[i],tp[i],ri[i],bo[i]);
		if(le[i]==l&&ri[i]==r&&tp[i]==t&&bo[i]==b)return printf("%d\n",i+1),0;
	}puts("-1");
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fill(A,B) memset(A,B,sizeof(A))
#define For(i,A,B) for(int i=(A);i<(int)(B);i++)
#define rep(i,A,B) for(int i=(A);i<=(B);i++)
#define dep(i,B,A) for(int i=(B);i>=(A);i--)
#define re(i,A) for(int i=0;i<(int)(A);i++)
#define de(i,A) for(int i=(A)-1;~i;i--)
#define inf (1<<30)
#define mn 100011
#define M 100000000003ll
#define si(x) ((int)x.size())
#define MAX(A,B) A=max(A,B)
#define MIN(A,B) A=min(A,B)
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
template<class T>inline void R(T &xx){xx=0;char ch=getchar();bool F=0;while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if(ch=='-')F=1,ch=getchar();while(ch>='0'&&ch<='9')xx=xx+xx+(xx<<3)+ch-48,ch=getchar();if(F)xx=-xx;}

int d,n,m,X1[mn],X2[mn],Y1[mn],Y2[mn];
vector<int>x1,x2,y1,y2;
int le[mn],tp[mn],bo[mn],ri[mn],l,r,t,b;
int main(){
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
    //freopen("2.out","w",stdout);
#endif
	R(d);
	R(n),R(m);
	re(i,d){
		R(X1[i]),R(Y1[i]),R(X2[i]),R(Y2[i]);
		if(X1[i]>X2[i])swap(X1[i],X2[i]);
		if(Y1[i]>Y2[i])swap(Y1[i],Y2[i]);

		x1.pb(X1[i]);
		y1.pb(Y1[i]);
		x2.pb(X2[i]);
		y2.pb(Y2[i]);
	}
	R(l),R(r),R(t),R(b);
	#define all(x) x.begin(),x.end()
	sort(all(x1));sort(all(x2));sort(all(y1));sort(all(y2));
	re(i,d){
		le[i]=lower_bound(all(x1),X2[i])-x1.begin()-(X1[i]!=X2[i]);
		tp[i]=lower_bound(all(y1),Y2[i])-y1.begin()-(Y1[i]!=Y2[i]);
		ri[i]=d-(upper_bound(all(x2),X1[i])-x2.begin())-(X1[i]!=X2[i]);
		bo[i]=d-(upper_bound(all(y2),Y1[i])-y2.begin())-(Y1[i]!=Y2[i]);
	//	printf("%d %d %d %d\n",le[i],tp[i],ri[i],bo[i]);
		if(le[i]==l&&ri[i]==r&&tp[i]==t&&bo[i]==b)return printf("%d\n",i+1),0;
	}puts("-1");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXX 100005
int D,N,M,cnt[4];
int mp[MXX][4];
typedef pair<pii,pii> pp;
vector<pp> pos;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>D>>N>>M;
    int x1,y1,x2,y2;
    //psum L,R,U,D
    FOR(i,1,D)
    {
        cin>>x1>>y1>>x2>>y2;
        pos.pb( mkp( mkp(x1,y1), mkp(x2,y2) ) );
        mp[min(x1,x2)][0]++;
        mp[max(x1,x2)][1]++;
        mp[min(y1,y2)][2]++;
        mp[max(y1,y2)][3]++;
    }
    FOR(i,0,3)cin>>cnt[i];

    FOR(i,1,N)mp[i][0]+=mp[i-1][0];
    FORD(i,N-1,0)mp[i][1]+=mp[i+1][1];
    FOR(i,1,M)mp[i][2]+=mp[i-1][2];
    FORD(i,M-1,0)mp[i][3]+=mp[i+1][3];

    int c[4];
    FOR(i,0,D-1)
    {
        x1 = pos[i].f.f, y1 = pos[i].f.s,
        x2 = pos[i].s.f, y2 = pos[i].s.s;

        c[0] = mp[max(x1,x2)-1][0];
        c[1] = mp[min(x1,x2)+1][1];
        if(x1!=x2)c[0]--,c[1]--;
        c[2] = mp[max(y1,y2)-1][2];
        c[3] = mp[min(y1,y2)+1][3];
        if(y1!=y2)c[2]--,c[3]--;
        bool f = false;
        //FOR(j,0,3)cout<<"meow "<<c[j]<<' ';
        //cout<<'\n';
        FOR(j,0,3)
        {
            if(c[j]!=cnt[j])f=true;
        }
        if(f)continue;
        cout<<i+1<<'\n';
        return 0;
    }
    cout<<-1<<'\n';

    return 0;
}
//hello


#include <bits/stdc++.h>
#define MAXN 100000
#define zeros(x) (x & (-x))

using namespace std;

struct Data {
    int x1;
    int y1;
    int x2;
    int y2;
}v[MAXN + 1];

int fr[MAXN + 1];

int aib[MAXN + 1];

inline void update(int p, int val) {
    for(int i = p; i <= MAXN; i += zeros(i))
        aib[i] += val;
}

inline int query(int p) {
    int ans = 0;
    for(int i = p; i > 0; i -= zeros(i))
        ans += aib[i];
    return ans;
}

int main() {
   // fstream cin("A.in");
   // ofstream cout("A.out");
    int n, m, i, d, cntl, cntr, cntb, cntt;
    ios::sync_with_stdio(false);
    cin >> d;
    cin >> n >> m;
    for(i = 1; i <= d; i++) {
        cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
        if(v[i].x1 > v[i].x2)
            swap(v[i].x1, v[i].x2);
        if(v[i].y1 > v[i].y2)
            swap(v[i].y1, v[i].y2);
    }
    cin >> cntl >> cntr >> cntt >> cntb;
    for(i = 1; i <= d; i++)
        update(v[i].x1, 1);
    for(i = 1; i <= d; i++) {
        update(v[i].x1, -1);
        if(query(v[i].x2 - 1) == cntl) {
           fr[i]++;
        }
        update(v[i].x1, 1);
    }
    memset(aib, 0, sizeof(aib));
    for(i = 1; i <= d; i++)
        update(v[i].x2, 1);
    for(i = 1; i <= d; i++) {
        update(v[i].x2, -1);
        if(query(MAXN) - query(v[i].x1) == cntr)
           fr[i]++;
        update(v[i].x2, 1);
    }
    memset(aib, 0, sizeof(aib));
    for(i = 1; i <= d; i++)
        update(v[i].y1, 1);
    for(i = 1; i <= d; i++) {
        update(v[i].y1, -1);
        if(query(v[i].y2 - 1) == cntt)
           fr[i]++;
        update(v[i].y1, 1);
    }
    memset(aib, 0, sizeof(aib));
    for(i = 1; i <= d; i++)
        update(v[i].y2, 1);
    for(i = 1; i <= d; i++) {
        update(v[i].y2, -1);
        if(query(MAXN) - query(v[i].y1) == cntb)
           fr[i]++;
        update(v[i].y2, 1);
    }
    for(i = 1; i <= n; i++) {
        if(fr[i] == 4) {
            cout << i;
            return 0;
        }
    }
    cout << -1;
   // cin.close();
   // cout.close();
    return 0;
}


#include <bits/stdc++.h>
#define MAXN 100000
#define zeros(x) (x & (-x))

using namespace std;

struct Data {
    int x1;
    int y1;
    int x2;
    int y2;
}v[MAXN + 1];

int fr[MAXN + 1];

int aib[MAXN + 1];

inline void update(int p, int val) {
    for(int i = p; i <= MAXN; i += zeros(i))
        aib[i] += val;
}

inline int query(int p) {
    int ans = 0;
    for(int i = p; i > 0; i -= zeros(i))
        ans += aib[i];
    return ans;
}

int main() {
    //fstream cin("A.in");
    //ofstream cout("A.out");
    int n, m, i, d, cntl, cntr, cntb, cntt;
    ios::sync_with_stdio(false);
    cin >> d;
    cin >> n >> m;
    for(i = 1; i <= d; i++) {
        cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
        if(v[i].x1 > v[i].x2)
            swap(v[i].x1, v[i].x2);
        if(v[i].y1 > v[i].y2)
            swap(v[i].y1, v[i].y2);
    }
    cin >> cntl >> cntr >> cntt >> cntb;
    for(i = 1; i <= d; i++)
        update(v[i].x1, 1);
    for(i = 1; i <= d; i++) {
        update(v[i].x1, -1);
        if(query(v[i].x2 - 1) == cntl)
           fr[i]++;
        update(v[i].x1, 1);
    }
    memset(aib, 0, sizeof(aib));
    for(i = 1; i <= d; i++)
        update(v[i].x2, 1);
    for(i = 1; i <= d; i++) {
        update(v[i].x2, -1);
        if(query(MAXN) - query(v[i].x1) == cntr)
           fr[i]++;
        update(v[i].x2, 1);
    }
    memset(aib, 0, sizeof(aib));
    for(i = 1; i <= d; i++)
        update(v[i].y1, 1);
    for(i = 1; i <= d; i++) {
        update(v[i].y1, -1);
        if(query(v[i].y2 - 1) == cntt)
           fr[i]++;
        update(v[i].y1, 1);
    }
    memset(aib, 0, sizeof(aib));
    for(i = 1; i <= d; i++)
        update(v[i].y2, 1);
    for(i = 1; i <= d; i++) {
        update(v[i].y2, -1);
        if(query(MAXN) - query(v[i].y1) == cntb)
           fr[i]++;
        update(v[i].y2, 1);
    }
    for(i = 1; i <= d; i++) {
        if(fr[i] == 4) {
            cout << i;
            return 0;
        }
    }
    cout << -1;
    //cin.close();
    //cout.close();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

vector<int>v[4];
int a[100005][4];

int search_dwn(int idx, int target){
  int lo = 0, hi = v[idx].size() - 1;

  while(lo < hi){
    int md = lo + (hi - lo + 1)/2;

    if(v[idx][md] < target)
      lo = md;
    else
      hi = md - 1;

  }
  if(v[idx][lo] == target)return 0;

  return  lo + 1;

}
int search_up(int idx, int target){
  int lo = 0, hi = v[idx].size() - 1;

  while(lo < hi){
    int md = lo + (hi - lo)/2;

    if(v[idx][md] > target)
      hi = md;
    else
      lo = md + 1;

  }

  if(v[idx][lo] == target)return 0;

  return v[idx].size() - lo;

}
int main(){

  int n;

  cin >> n;

  int x;

  cin >> x >> x;

  for(int i = 0; i < n; i++){
    for(int j = 0;j < 4; j++)scanf("%d", &a[i][j]);

    if(a[i][0] > a[i][2])swap(a[i][0], a[i][2]);
    if(a[i][1] > a[i][3])swap(a[i][1], a[i][3]);

    for(int j = 0; j < 4; j++)v[j].push_back(a[i][j]);

  }

  for(int j = 0; j < 4; j++)sort(v[j].begin(), v[j].end());

  int cntl, cntr, cntt, cntb;

  cin >> cntl >> cntr >> cntt >> cntb;

  for(int i = 0; i < n; i++){

    int lft = search_dwn(0, a[i][2]) - (a[i][0] != a[i][2]);
    int dwn = search_dwn(1, a[i][3]) - (a[i][1] != a[i][3]);
    int up = search_up(3, a[i][1]) - (a[i][1] != a[i][3]);
    int rt = search_up(2, a[i][0])- (a[i][0] != a[i][2]);

  //  cout << lft << ' ' << rt << ' ' << up << ' ' << dwn << '\n';
    swap(up, dwn);

    if(cntl == lft && cntr == rt && up == cntt && cntb == dwn)
      return cout << i + 1 << '\n', 0;

  }

  puts("-1");

  return 0;

}


#include <bits/stdc++.h>
using namespace std;

vector<int>v[4];
int a[100005][4];

int search_dwn(int idx, int target){
  int lo = 0, hi = v[idx].size() - 1;

  while(lo < hi){
    int md = lo + (hi - lo + 1)/2;

    if(v[idx][md] < target)
      lo = md;
    else
      hi = md - 1;

  }
  if(v[idx][lo] == target)return 0;

  return  lo + 1;

}
int search_up(int idx, int target){
  int lo = 0, hi = v[idx].size() - 1;

  while(lo < hi){
    int md = lo + (hi - lo)/2;

    if(v[idx][md] > target)
      hi = md;
    else
      lo = md + 1;

  }

  if(v[idx][lo] == target)return 0;

  return v[idx].size() - lo;

}
int main(){

  int n;

  cin >> n;

  int x;

  cin >> x >> x;

  for(int i = 0; i < n; i++){
    for(int j = 0;j < 4; j++)scanf("%d", &a[i][j]);

    if(a[i][0] > a[i][2])swap(a[i][0], a[i][2]);
    if(a[i][1] > a[i][3])swap(a[i][1], a[i][3]);

    for(int j = 0; j < 4; j++)v[j].push_back(a[i][j]);

  }

  for(int j = 0; j < 4; j++)sort(v[j].begin(), v[j].end());

  int cntl, cntr, cntt, cntb;

  cin >> cntl >> cntr >> cntt >> cntb;

  for(int i = 0; i < n; i++){

    int lft = search_dwn(0, a[i][2]) - (a[i][0] != a[i][2]);
    int dwn = search_dwn(1, a[i][3]) - (a[i][1] != a[i][3]);
    int up = search_up(3, a[i][1]) - (a[i][1] != a[i][3]);
    int rt = search_up(2, a[i][0])- (a[i][0] != a[i][2]);

  //  cout << lft << ' ' << rt << ' ' << up << ' ' << dwn << '\n';
    swap(up, dwn);

    if(cntl == lft && cntr == rt && up == cntt && cntb == dwn)
      return printf("%d\n", i + 1);

  }

  puts("-1");

  return 0;

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define pb(a) push_back(a)
#define fir first
#define se second
#define LL unsigned long long
typedef pair<int,int> pii;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
const int maxn = 3e5+5;
const int inf = 0x3f3f3f3f;
LL mod = 1e9+7;
double PI = acos(-1);

struct node {
	int x1,y1,x2,y2;
} num[maxn];

pii dx[maxn],dy[maxn];
int v1[maxn],vis[maxn],v2[maxn],v3[maxn],v4[maxn],ncnt[maxn];

int main() {
	int n,a,b;
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	for(int i = 1;i <= n;i++) {
		scanf("%d%d%d%d",&num[i].x1,&num[i].y1,&num[i].x2,&num[i].y2);
	}
	for(int i = 1;i <= n;i++) {
		dx[i*2-1].fir = num[i].x1;
		dx[i*2].fir = num[i].x2;
		dy[i*2-1].fir = num[i].y1;
		dy[i*2].fir = num[i].y2;
		dx[i*2-1].se = dx[i*2].se = dy[i*2-1].se = dy[i*2].se = i;
	}
	sort(dx+1,dx+1+2*n);
	sort(dy+1,dy+1+2*n);
	//for(int i = 1;i <= 2*n;i++) cout<<dx[i].fir<<" "<<dx[i].se<<endl;
	int cntl,cntr,cntt,cntb;
	scanf("%d%d%d%d",&cntl,&cntr,&cntt,&cntb);
	int cnt = 0;
	clr(vis,0);
	clr(v1,0);
	clr(v2,0);
	clr(v3,0);
	clr(v4,0);
	ncnt[0] = -1;
	for(int i = 1;i <= 2*n;i++) {
		if(cnt == cntl && !vis[dx[i].se] && dx[i].fir > ncnt[cnt]) {
			v1[dx[i].se]++;
			//cout<<i<<"  fff"<<endl;
		}
		if(cnt == cntl+1 && vis[dx[i].se] && dx[i].fir > ncnt[cnt]) {
			v1[dx[i].se]++;
			//cout<<i<<"  fff"<<endl;
		}
		if(vis[dx[i].se] == 0) {
			vis[dx[i].se] = 1;
			cnt++;
			ncnt[cnt] = dx[i].fir;
		}
	}
	cnt = 0;
	clr(vis,0);
	for(int i = 1;i <= 2*n;i++) {
		if(cnt == cntt && !vis[dy[i].se] && dy[i].fir > ncnt[cnt]) {
			v2[dy[i].se]++;
		}
		if(cnt == cntt+1 && vis[dy[i].se] && dy[i].fir > ncnt[cnt]) {
			v2[dy[i].se]++;
		}
		if(vis[dy[i].se] == 0) {
			vis[dy[i].se] = 1;
			cnt++;
			ncnt[cnt] = dy[i].fir;
		}
	}
	cnt = 0;
	clr(vis,0);
	ncnt[0] = inf;
	for(int i = 2*n;i >= 1;i--) {
		if(cnt == cntr && !vis[dx[i].se] && dx[i].fir < ncnt[cnt]) v3[dx[i].se]++;
		if(cnt == cntr+1 && vis[dx[i].se] && dx[i].fir < ncnt[cnt]) {
			v3[dx[i].se]++;
		}
		if(vis[dx[i].se] == 0) {
			vis[dx[i].se] = 1;
			cnt++;
			ncnt[cnt] = dx[i].fir;
		}
	}
	cnt = 0;
	clr(vis,0);
	for(int i = 2*n;i >= 1;i--) {
		if(cnt == cntb && !vis[dy[i].se] && dy[i].fir < ncnt[cnt]) v4[dy[i].se]++;
		if(cnt == cntb+1 && vis[dy[i].se] && dy[i].fir < ncnt[cnt]) {
			v4[dy[i].se]++;
		}
		if(vis[dy[i].se] == 0) {
			vis[dy[i].se] = 1;
			cnt++;
			ncnt[cnt] = dy[i].fir;
		}
	}
	int ans = -1;
	for(int i = 1;i <= n;i++) if(v1[i] && v2[i] && v3[i] && v4[i]) ans = i;
	cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define pb(a) push_back(a)
#define fir first
#define se second
#define LL unsigned long long
typedef pair<int,int> pii;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
const int maxn = 3e5+5;
const int inf = 0x3f3f3f3f;
LL mod = 1e9+7;
double PI = acos(-1);

struct node {
	int x1,y1,x2,y2;
} num[maxn];

pii dx[maxn],dy[maxn];
int v1[maxn],vis[maxn],v2[maxn],v3[maxn],v4[maxn];

int main() {
	int n,a,b;
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	for(int i = 1;i <= n;i++) {
		scanf("%d%d%d%d",&num[i].x1,&num[i].y1,&num[i].x2,&num[i].y2);
	}
	for(int i = 1;i <= n;i++) {
		dx[i*2-1].fir = num[i].x1;
		dx[i*2].fir = num[i].x2;
		dy[i*2-1].fir = num[i].y1;
		dy[i*2].fir = num[i].y2;
		dx[i*2-1].se = dx[i*2].se = dy[i*2-1].se = dy[i*2].se = i;
	}
	sort(dx+1,dx+1+2*n);
	sort(dy+1,dy+1+2*n);
	//for(int i = 1;i <= 2*n;i++) cout<<dx[i].fir<<" "<<dx[i].se<<endl;
	int cntl,cntr,cntt,cntb;
	scanf("%d%d%d%d",&cntl,&cntr,&cntt,&cntb);
	int cnt = 0;
	clr(vis,0);
	clr(v1,0);
	clr(v2,0);
	clr(v3,0);
	clr(v4,0);
	for(int i = 1;i <= 2*n;i++) {
		if(cnt == cntl && !vis[dx[i].se]) {
			v1[dx[i].se]++;
			//cout<<i<<"  fff"<<endl;
		}
		if(cnt == cntl+1 && vis[dx[i].se] && dx[i].fir > dx[i-1].fir) {
			v1[dx[i].se]++;
			//cout<<i<<"  fff"<<endl;
		}
		if(vis[dx[i].se] == 0) {
			vis[dx[i].se] = 1;
			cnt++;
		}
	}
	cnt = 0;
	clr(vis,0);
	for(int i = 1;i <= 2*n;i++) {
		if(cnt == cntt && !vis[dy[i].se]) {
			v2[dy[i].se]++;
		}
		if(cnt == cntt+1 && vis[dy[i].se] && dy[i].fir > dy[i-1].fir) {
			v2[dy[i].se]++;
		}
		if(vis[dy[i].se] == 0) {
			vis[dy[i].se] = 1;
			cnt++;
		}
	}
	cnt = 0;
	clr(vis,0);
	for(int i = 2*n;i >= 1;i--) {
		if(cnt == cntr && !vis[dx[i].se]) v3[dx[i].se]++;
		if(cnt == cntr+1 && vis[dx[i].se] && dx[i].fir > dx[i+1].fir) {
			v3[dx[i].se]++;
		}
		if(vis[dx[i].se] == 0) {
			vis[dx[i].se] = 1;
			cnt++;
		}
	}
	cnt = 0;
	clr(vis,0);
	for(int i = 2*n;i >= 1;i--) {
		if(cnt == cntb && !vis[dy[i].se]) v4[dy[i].se]++;
		if(cnt == cntb+1 && vis[dy[i].se] && dy[i].fir > dy[i+1].fir) {
			v4[dy[i].se]++;
		}
		if(vis[dy[i].se] == 0) {
			vis[dy[i].se] = 1;
			cnt++;
		}
	}
	int ans = -1;
	for(int i = 1;i <= n;i++) if(v1[i] && v2[i] && v3[i] && v4[i]) ans = i;
	cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define pb(a) push_back(a)
#define fir first
#define se second
#define LL unsigned long long
typedef pair<int,int> pii;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
const int maxn = 1e5+5;
const int inf = 0x3f3f3f3f;
LL mod = 1e9+7;
double PI = acos(-1);

struct node {
	int x1,y1,x2,y2;
} num[maxn];

int dx1[maxn],dx2[maxn],dy1[maxn],dy2[maxn],vis[maxn];

bool cmp(int a,int b) {
	return a>b;
}

int main() {
	int n,a,b;
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	for(int i = 1;i <= n;i++) {
		scanf("%d%d%d%d",&num[i].x1,&num[i].y1,&num[i].x2,&num[i].y2);
		dx1[i] = min(num[i].x1,num[i].x2);
		dx2[i] = max(num[i].x1,num[i].x2);
		dy1[i] = min(num[i].y1,num[i].y2);
		dy2[i] = max(num[i].y1,num[i].y2);
	}
	int cntl,cntr,cntt,cntb;
	scanf("%d%d%d%d",&cntl,&cntr,&cntt,&cntb);
	sort(dx1+1,dx1+1+n);
	sort(dx2+1,dx2+1+n,cmp);
	sort(dy1+1,dy1+1+n);
	sort(dy2+1,dy2+1+n,cmp);
	clr(vis,0);
	for(int i = 1;i <= n;i++) {
		int dd = max(num[i].x1,num[i].x2);
		int l = 1,r = n+1,dd1 = max(num[i].x1,num[i].x2);
		while(l+1 < r) {
			int mid = (l+r)>>1;
			if(dx1[mid] < dd1) l = mid;
			else r = mid;
		}
		if(num[i].x1 != num[i].x2) l--;
		if(l == cntl) vis[i]++;

		l = 1,r = n+1,dd1 = max(num[i].y1,num[i].y2);
		while(l+1 < r) {
			int mid = (l+r)>>1;
			if(dy1[mid] < dd1) l = mid;
			else r = mid;
		}
		if(num[i].y1 != num[i].y2) l--;
		if(l == cntt) vis[i]++;

		l = 0,r = n+1,dd1 = min(num[i].x1,num[i].x2);
		while(l+1 < r) {
			int mid = (l+r)>>1;
			if(dx2[mid] <= dd1) r = mid;
			else l = mid;
		}
		if(num[i].x1 != num[i].x2) l--;
		if(l == cntr) vis[i]++;

		l = 0,r = n+1,dd1 = min(num[i].y1,num[i].y2);
		while(l+1 < r) {
			int mid = (l+r)>>1;
			if(dy2[mid] <= dd1) r = mid;
			else l = mid;
		}
		if(num[i].y1 != num[i].y2) l--;
		if(l == cntb) vis[i]++;
	}
	int ans = -1;
	for(int i = 1;i <= n;i++) {
		if(vis[i] >= 4) ans = i;
	}
	cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define pb(a) push_back(a)
#define fir first
#define se second
#define LL unsigned long long
typedef pair<int,int> pii;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
const int maxn = 3e5+5;
const int inf = 0x3f3f3f3f;
LL mod = 1e9+7;
double PI = acos(-1);

struct node {
	int x1,y1,x2,y2;
} num[maxn];

pii dx[maxn],dy[maxn];
int v1[maxn],vis[maxn],v2[maxn],v3[maxn],v4[maxn];

int main() {
	int n,a,b;
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	for(int i = 1;i <= n;i++) {
		scanf("%d%d%d%d",&num[i].x1,&num[i].y1,&num[i].x2,&num[i].y2);
	}
	for(int i = 1;i <= n;i++) {
		dx[i*2-1].fir = num[i].x1;
		dx[i*2].fir = num[i].x2;
		dy[i*2-1].fir = num[i].y1;
		dy[i*2].fir = num[i].y2;
		dx[i*2-1].se = dx[i*2].se = dy[i*2-1].se = dy[i*2].se = i;
	}
	sort(dx+1,dx+1+2*n);
	sort(dy+1,dy+1+2*n);
	//for(int i = 1;i <= 2*n;i++) cout<<dx[i].fir<<" "<<dx[i].se<<endl;
	int cntl,cntr,cntt,cntb;
	scanf("%d%d%d%d",&cntl,&cntr,&cntt,&cntb);
	int cnt = 0;
	clr(vis,0);
	clr(v1,0);
	clr(v2,0);
	clr(v3,0);
	clr(v4,0);
	for(int i = 1;i <= 2*n;i++) {
		if(cnt == cntl && !vis[dx[i].se]) {
			v1[dx[i].se]++;
			//cout<<i<<"  fff"<<endl;
		}
		if(cnt == cntl+1 && vis[dx[i].se]) {
			v1[dx[i].se]++;
			//cout<<i<<"  fff"<<endl;
		}
		if(vis[dx[i].se] == 0) {
			vis[dx[i].se] = 1;
			cnt++;
		}
	}
	cnt = 0;
	clr(vis,0);
	for(int i = 1;i <= 2*n;i++) {
		if(cnt == cntt && !vis[dy[i].se]) {
			v2[dy[i].se]++;
		}
		if(cnt == cntt+1 && vis[dy[i].se]) {
			v2[dy[i].se]++;
		}
		if(vis[dy[i].se] == 0) {
			vis[dy[i].se] = 1;
			cnt++;
		}
	}
	cnt = 0;
	clr(vis,0);
	for(int i = 2*n;i >= 1;i--) {
		if(cnt == cntr && !vis[dx[i].se]) v3[dx[i].se]++;
		if(cnt == cntr+1 && vis[dx[i].se]) {
			v3[dx[i].se]++;
		}
		if(vis[dx[i].se] == 0) {
			vis[dx[i].se] = 1;
			cnt++;
		}
	}
	cnt = 0;
	clr(vis,0);
	for(int i = 2*n;i >= 1;i--) {
		if(cnt == cntb && !vis[dy[i].se]) v4[dy[i].se]++;
		if(cnt == cntb+1 && vis[dy[i].se]) {
			v4[dy[i].se]++;
		}
		if(vis[dy[i].se] == 0) {
			vis[dy[i].se] = 1;
			cnt++;
		}
	}
	int ans = -1;
	for(int i = 1;i <= n;i++) if(v1[i] && v2[i] && v3[i] && v4[i]) ans = i;
	cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
#define clr(a,b) memset(a,b,sizeof(a))
#define pb(a) push_back(a)
#define fir first
#define se second
#define LL unsigned long long
typedef pair<int,int> pii;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
const int maxn = 1e5+5;
const int inf = 0x3f3f3f3f;
LL mod = 1e9+7;
double PI = acos(-1);

struct node {
	int x1,y1,x2,y2;
} num[maxn];

int dx1[maxn],dx2[maxn],dy1[maxn],dy2[maxn],vis[maxn];

bool cmp(int a,int b) {
	return a>b;
}

int main() {
	int n,a,b;
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	for(int i = 1;i <= n;i++) {
		scanf("%d%d%d%d",&num[i].x1,&num[i].y1,&num[i].x2,&num[i].y2);
		dx1[i] = min(num[i].x1,num[i].x2);
		dx2[i] = max(num[i].x1,num[i].x2);
		dy1[i] = min(num[i].y1,num[i].y2);
		dy2[i] = max(num[i].y1,num[i].y2);
	}
	int cntl,cntr,cntt,cntb;
	scanf("%d%d%d%d",&cntl,&cntr,&cntt,&cntb);
	sort(dx1+1,dx1+1+n);
	sort(dx2+1,dx2+1+n,cmp);
	sort(dy1+1,dy1+1+n);
	sort(dy2+1,dy2+1+n,cmp);
	clr(vis,0);
	for(int i = 1;i <= n;i++) {
		int dd = max(num[i].x1,num[i].x2);
		int l = 0,r = n+1,dd1 = max(num[i].x1,num[i].x2);
		while(l+1 < r) {
			int mid = (l+r)>>1;
			if(dx1[mid] < dd1) l = mid;
			else r = mid;
		}
		if(num[i].x1 != num[i].x2) l--;
		if(l == cntl) vis[i]++;

		l = 0,r = n+1,dd1 = max(num[i].y1,num[i].y2);
		while(l+1 < r) {
			int mid = (l+r)>>1;
			if(dy1[mid] < dd1) l = mid;
			else r = mid;
		}
		if(num[i].y1 != num[i].y2) l--;
		if(l == cntt) vis[i]++;

		l = 0,r = n+1,dd1 = min(num[i].x1,num[i].x2);
		while(l+1 < r) {
			int mid = (l+r)>>1;
			if(dx2[mid] <= dd1) r = mid;
			else l = mid;
		}
		if(num[i].x1 != num[i].x2) l--;
		if(l == cntr) vis[i]++;

		l = 0,r = n+1,dd1 = min(num[i].y1,num[i].y2);
		while(l+1 < r) {
			int mid = (l+r)>>1;
			if(dy2[mid] <= dd1) r = mid;
			else l = mid;
		}
		if(num[i].y1 != num[i].y2) l--;
		if(l == cntb) vis[i]++;
	}
	int ans = -1;
	for(int i = 1;i <= n;i++) {
		if(vis[i] >= 4) ans = i;
	}
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define e 2.7183
const int N=2e5+5;
vector<string>v;
map<ll,ll>mp;
map<ll,ll>::iterator it;
set<ll>h;
ll ctl[N];
ll ctr[N];
ll ctt[N];
ll ctb[N];
ll ax[N];
ll bx[N];
ll ay[N];
ll by[N];
int main()
{
    ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
    ll n,t,y=0,i,x=0,d,p,cnt=0,ans=0,l,r,m,cntl,cntr,cntt,cntb,w=0,j,mod=1e9+7,b,x1,y1;
	cin>>d>>n>>m;
	for(int i=1;i<=d;i++)
    {
		cin>>x>>y>>x1>>y1;
		ax[i]=x,ay[i]=y,bx[i]=x1,by[i]=y1;
		ctl[min(x, x1)]++;
		ctr[max(x, x1)]++;
		ctt[min(y, y1)]++;
		ctb[max(y, y1)]++;
	}
	for(int i=1;i<=100000;i++)
	{
		ctl[i]+=ctl[i-1];
		ctt[i]+=ctt[i-1];
	}
	for (int i=100000;i>=1;i--)
	{
		ctr[i]+=ctr[i+1];
		ctb[i]+=ctb[i+1];
	}
	cin>>x>>y>>x1>>y1;
	for(int i=1;i<=d;i+=1)
	{

		l=ctl[max(ax[i],bx[i])-1];
		r=ctr[min(ax[i],bx[i])+1];
		t=ctt[max(ay[i],by[i])-1];
		b=ctb[min(ay[i],by[i])+1];
		if(ax[i]!=bx[i])
        l--,r--;
		if(ay[i]!=by[i])
        t--,b--;
		if(l==x&&r==y&&t==x1&&b==y1)
        return cout<<i,0;
	}
	cout<<-1;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define e 2.7183
const int N=2e5+5;
vector<string>v;
map<ll,ll>mp;
map<ll,ll>::iterator it;
set<ll>h;
ll ctl[N];
ll ctr[N];
ll ctt[N];
ll ctb[N];
ll ax[N];
ll bx[N];
ll ay[N];
ll by[N];
int main()
{
    ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
    ll n,t,y=0,i,x=0,d,p,cnt=0,ans=0,l,r,m,cntl,cntr,cntt,cntb,w=0,j,mod=1e9+7,b,x1,y1;
	cin>>d>>n>>m;
	for(int i=1;i<=d;i++)
    {
		cin>>x>>y>>x1>>y1;
		ax[i]=x,ay[i]=y,bx[i]=x1,by[i]=y1;
		ctl[min(x, x1)]++;
		ctr[max(x, x1)]++;
		ctt[min(y, y1)]++;
		ctb[max(y, y1)]++;
	}
	for (int i=1;i<=100000;i++)
	{
		ctl[i]+=ctl[i-1];
        ctt[i]+=ctt[i-1];
        ctr[i]+=ctr[i+1];
        ctb[i]+=ctb[i+1];
	}
	cin>>x>>y>>x1>>y1;
	for(int i=1;i<=d;i+=1)
	{

		l=ctl[max(ax[i],bx[i])-1];
		r=ctr[min(ax[i],bx[i])+1];
		t=ctt[max(ay[i],by[i])-1];
		b=ctb[min(ay[i],by[i])+1];
		if(ax[i]!=bx[i])
        l--,r--;
		if(ay[i]!=by[i])
        t--,b--;
		if(l==x&&r==y&&t==x1&&b==y1)
        return cout<<i,0;
	}
	cout<<-1;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int 	ll;
typedef pair<int,int>   ii;
typedef vector< ii >   vii;
typedef vector<int>     vi;
typedef vector< vi >   vvi;

#define mm 100005
#define nn 1005
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define cases int t;  cin>>t;   while(t--)
#define check(a,n) forn(iiii,int(n)) cout<<int(a[iiii])<<" "; cout<<endl
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vi x1,y1,x2,y2;
int cl,cr,cd,cu,n,a[mm],b[mm],c[mm],d[mm],r[mm],l[mm],u[mm],bo[mm];

int main()
{
    fast_io;
    cin>>n>>a[0]>>a[0];
    forn(i,n)
    {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        if(a[i]>c[i]) swap(a[i],c[i]);
        if(b[i]>d[i]) swap(b[i],d[i]);
        x1.pb(a[i]);
        x2.pb(c[i]);
        y1.pb(b[i]);
        y2.pb(d[i]);
    }
    cin>>cl>>cr>>cu>>cd;
    sort(all(x1));
    sort(all(x2));
    sort(all(y1));
    sort(all(y2));
    /*check(x1,n);
    check(x2,n);
    check(y1,n);
    check(y2,n);
    */forn(i,n)
    {
        l[i]=lower_bound(all(x1),c[i])-x1.begin();
        if(a[i]<c[i]) l[i]--;
        r[i]=n-(upper_bound(all(x2),a[i])-x2.begin());
        if(a[i]<c[i]) r[i]--;
        u[i]=lower_bound(all(y1),d[i])-y1.begin();
        if(b[i]<d[i]) u[i]--;
        bo[i]=n-(upper_bound(all(y2),b[i])-y2.begin());
        if(b[i]<d[i]) bo[i]--;
       // cout<<l[i]<<" "<<r[i]<<" "<<u[i]<<" "<<bo[i]<<endl;
    }
    forn(i,n)
        if(l[i]==cl&&r[i]==cr&&u[i]==cu&&bo[i]==cd)
            return cout<<i+1,0;
    cout<<-1;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int 	ll;
typedef pair<int,int>   ii;
typedef vector< ii >   vii;
typedef vector<int>     vi;
typedef vector< vi >   vvi;

#define mm 100005
#define nn 1005
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define rep(i, a, b) for(int i = int(a); i < int(b); ++i)
#define cases int t;  cin>>t;   while(t--)
#define check(a,n) forn(iiii,int(n)) cout<<int(a[iiii+1])<<" "; cout<<endl
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int cnt[10*mm],vis[10*mm];

int main()
{
    fast_io;
    int n,m,a[mm],flag=1;
    scanf("%d%d",&n,&m);
    int last=n;
    forn(i,n)
    {
        scanf("%d",&a[i]);
        if(a[i]==m) last=i;
    }
    if(last==n)
    {
        printf("%d",a[0]);
        return 0;
    }
    set<ii> s;
    forn(i,n)
    {
        if(a[i]!=m)
        {
            if(vis[a[i]]!=2&&flag==0) continue;
            if(cnt[a[i]]==0)
            {
                s.insert({1,a[i]});
            }
            else
            {
                s.erase({cnt[a[i]],a[i]});
                s.insert({cnt[a[i]]+1,a[i]});
            }
            cnt[a[i]]++;
        }
        else
        {

            cnt[a[i]]++;
            for(auto it:s)
            {
                if(it.ff>=cnt[a[i]])
                    break;
                else
                    vis[it.ss]=1,s.erase(it);
            }
            if(sz(s)==0)
            {
                cout<<-1;
                return 0;
            }
            if(flag)
            {
                flag=0;
                for(auto it:s)
                    vis[it.ss]=2;
            }
            if(last==i)
            {
                for(auto it:s)
                {
                    printf("%d",it.ss);
                    break;
                }
                return 0;
            }
        }/*
        for(auto it:s)
            cout<<it.ff<<" "<<it.ss<<endl;
        cout<<endl;*/
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define Pi 3.141592653589793
#define eps 1e-9
#define MOD 1000000007
#define SQR(n) ((n)*(n))
#define MEM(a,val) memset(a,val,sizeof(a))
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vii vector< vector<int> >
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define SS stringstream
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORD(i,a,b) for(int i = b; i >= a; i--)
#define ul unsigned long
#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define fast_io ios_base::sync_with_stdio(false)
#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

ll mod(ll a, ll b) // calculates a%b, not remainder
{
	ll ans;
	if(b == 0)
		return -1;
	else
	{
		ans = (a<0 ? mod(((a%b)+b),b) : a%b);
	}
	return ans;
}
vi cntl(100003,0),cntr(100003,0),cntt(100003,0),cntb(100003,0);
int n,m,d;
void solve(){
	int cl,cb,cr,ct;
	cin >> d >> n >> m;
	vi x1(d+1),x2(d+1),y1(d+1),y2(d+1);
	FOR(i,1,d+1){
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		cntl[min(x1[i],x2[i])]++;
		cntr[max(x1[i],x2[i])]++;
		cntt[min(y1[i],y2[i])]++;
		cntb[max(y1[i],y2[i])]++;
	}
	FOR(i,1,100003){
		cntl[i]+=cntl[i-1];
		cntt[i]+=cntt[i-1];
	}
	FORD(i,1,100001){
		cntb[i]+=cntb[i+1];
		cntr[i]+=cntr[i+1];
	}
	cin >> cl >> cr >> ct >> cb;
	vector< pair<pii,pii> > cnt(d); // cnt.F.F =l,cnt.F.S = r,cnt.S.F =t,cnt.S.S=b
	FOR(i,1,d+1){
		cnt[i-1].F.F = cntl[max(x1[i],x2[i])-1]-(x1[i]!=x2[i]);
		//cout << cnt[i].F.F << " ";
		cnt[i-1].F.S = cntr[min(x1[i],x2[i])+1]-(x1[i]!=x2[i]);
		//cout << cnt[i].F.S<<" ";
		cnt[i-1].S.F = cntt[max(y1[i],y2[i])-1]-(y1[i]!=y2[i]);
		//cout << cnt[i].S.F<<" ";
		cnt[i-1].S.S = cntb[min(y1[i],y2[i])+1]-(y1[i]!=y2[i]);
		//cout <<cnt[i].S.S<<endl;
	}
	pair<pii,pii> target = {{cl,cr},{ct,cb}};
	if(find(all(cnt),target) != cnt.end()){
		cout << distance(cnt.begin(),find(all(cnt),target))+1<< endl;
	}
	else cout << -1 << endl;
}
int main()
{
	fast_io;
	//ifstream in_file("file.in");
	//ofstream out_file("file.out");
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define Pi 3.141592653589793
#define eps 1e-9
#define MOD 1000000007
#define SQR(n) ((n)*(n))
#define MEM(a,val) memset(a,val,sizeof(a))
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vii vector< vector<int> >
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define SS stringstream
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORD(i,a,b) for(int i = b; i >= a; i--)
#define ul unsigned long
#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define fast_io ios_base::sync_with_stdio(false)
#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

ll mod(ll a, ll b) // calculates a%b, not remainder
{
	ll ans;
	if(b == 0)
		return -1;
	else
	{
		ans = (a<0 ? mod(((a%b)+b),b) : a%b);
	}
	return ans;
}
vi cntl(100003,0),cntr(100003,0),cntt(100003,0),cntb(100003,0);
int n,m,d;
void solve(){
	int cl,cb,cr,ct;
	cin >> d >> n >> m;
	vi x1(d+1),x2(d+1),y1(d+1),y2(d+1);
	FOR(i,1,d+1){
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		cntl[min(x1[i],x2[i])]++;
		cntr[max(x1[i],x2[i])]++;
		cntt[min(y1[i],y2[i])]++;
		cntb[max(y1[i],y2[i])]++;
	}
	FOR(i,1,100003){
		cntl[i]+=cntl[i-1];
		cntt[i]+=cntt[i-1];
	}
	FORD(i,1,100001){
		cntb[i]+=cntb[i+1];
		cntr[i]+=cntr[i+1];
	}
	cin >> cl >> cr >> ct >> cb;
	vector< pair<pii,pii> > cnt(d+1); // cnt.F.F =l,cnt.F.S = r,cnt.S.F =t,cnt.S.S=b
	FOR(i,1,d+1){
		cnt[i].F.F = cntl[max(x1[i],x2[i])-1]-(x1[i]!=x2[i]);
		//cout << cnt[i].F.F << " ";
		cnt[i].F.S = cntr[min(x1[i],x2[i])+1]-(x1[i]!=x2[i]);
		//cout << cnt[i].F.S<<" ";
		cnt[i].S.F = cntt[max(y1[i],y2[i])-1]-(y1[i]!=y2[i]);
		//cout << cnt[i].S.F<<" ";
		cnt[i].S.S = cntb[min(y1[i],y2[i])+1]-(y1[i]!=y2[i]);
		//cout <<cnt[i].S.S<<endl;
	}
	pair<pii,pii> target = {{cl,cr},{ct,cb}};
	if(find(all(cnt),target) != cnt.end()){
		cout << find(all(cnt),target)-cnt.begin()<< endl;
	}
	else cout << -1 << endl;
}
int main()
{
	fast_io;
	//ifstream in_file("file.in");
	//ofstream out_file("file.out");
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>

using namespace std;

#define sz(X) ((int)(X).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(X) (X).begin(),(X).end()
#define FOR(i, a, n) for(int i=(a), __ ## i=(n); i<__ ## i; i++)
#define REP(I,N) FOR(I,0,N)
#define PR(X) cout<<#X<<" = "<<(X)<<" "
#define PRL cout<<endl
#define PRV(X) {cout<<#X<<" = {";REP(__prv,sz(X)-1)cout<<(X)[__prv]<<",";if(sz(X))cout<<*(X).end();cout<<"}"<<endl;}

template<class T> ostream &operator<<(ostream &os, const vector<T> &vec)
{
	os << '{';
	REP(i, sz(vec))
	{
		os << vec[i];
		if (i + 1 != sz(vec))
			os << ',';
	}
	os << '}';
	return os;
}

template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &par)
{
	os << '(' << par.X << ',' << par.Y << ')';
	return os;
}

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<unsigned long long> VULL;
typedef vector<vector<int>> VVI;
typedef queue<int> QI;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : abs(x);
}

template<class T> T sqr(T x)
{
	return x * x;
}

int sofa[100000][4];
int cntl[100001];
int cntr[100001];
int cntt[100001];
int cntb[100001];

int main()
{
	ios::sync_with_stdio(false);

	int d, n, m;
	cin >> d >> n >> m;
	REP(i, d)
		REP(j, 4)
		cin >> sofa[i][j];
	int cl, cr, ct, cb;
	cin >> cl >> cr >> ct >> cb;

	REP(i, d)
	{
		cntl[min(sofa[i][0], sofa[i][2])]++;
		cntr[max(sofa[i][0], sofa[i][2])]++;
		cntt[min(sofa[i][1], sofa[i][3])]++;
		cntb[max(sofa[i][1], sofa[i][3])]++;
	}

	FOR(i, 1, m)
	{
		cntl[i + 1] += cntl[i];
		cntr[m - i] += cntr[m + 1 - i];
	}
	FOR(i, 1, n)
	{
		cntt[i + 1] += cntt[i];
		cntb[n - i] += cntb[n + 1 - i];
	}

	REP(i, d)
	{
		if (cl == (cntl[max(sofa[i][0], sofa[i][2]) - 1] - (sofa[i][0] != sofa[i][2]))
			&& cr == (cntr[min(sofa[i][0], sofa[i][2]) + 1] - (sofa[i][0] != sofa[i][2]))
			&& cb == (cntb[min(sofa[i][1], sofa[i][3]) + 1] - (sofa[i][1] != sofa[i][3]))
			&& ct == (cntt[max(sofa[i][1], sofa[i][3]) - 1] - (sofa[i][1] != sofa[i][3]))) {
			cout << i + 1;
			return 0;
		}
	}

	cout << -1;

	return 0;
}


#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>

using namespace std;

#define sz(X) ((int)(X).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(X) (X).begin(),(X).end()
#define FOR(i, a, n) for(int i=(a), __ ## i=(n); i<__ ## i; i++)
#define REP(I,N) FOR(I,0,N)
#define PR(X) cout<<#X<<" = "<<(X)<<" "
#define PRL cout<<endl
#define PRV(X) {cout<<#X<<" = {";REP(__prv,sz(X)-1)cout<<(X)[__prv]<<",";if(sz(X))cout<<*(X).end();cout<<"}"<<endl;}

template<class T> ostream &operator<<(ostream &os, const vector<T> &vec)
{
	os << '{';
	REP(i, sz(vec))
	{
		os << vec[i];
		if (i + 1 != sz(vec))
			os << ',';
	}
	os << '}';
	return os;
}

template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &par)
{
	os << '(' << par.X << ',' << par.Y << ')';
	return os;
}

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<unsigned long long> VULL;
typedef vector<vector<int>> VVI;
typedef queue<int> QI;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : abs(x);
}

template<class T> T sqr(T x)
{
	return x * x;
}

int sofa[100000][4];
int cntl[100002];
int cntr[100002];
int cntt[100002];
int cntb[100002];

int main()
{
	ios::sync_with_stdio(false);

	int d, n, m;
	cin >> d >> n >> m;
	REP(i, d)
		REP(j, 4)
		cin >> sofa[i][j];
	int cl, cr, ct, cb;
	cin >> cl >> cr >> ct >> cb;

	REP(i, d)
	{
		cntl[min(sofa[i][0], sofa[i][2])]++;
		cntr[max(sofa[i][0], sofa[i][2])]++;
		cntt[min(sofa[i][1], sofa[i][3])]++;
		cntb[max(sofa[i][1], sofa[i][3])]++;
	}

	FOR(i, 1, n)
	{
		cntl[i + 1] += cntl[i];
		cntr[n - i] += cntr[n + 1 - i];
	}
	FOR(i, 1, m)
	{
		cntt[i + 1] += cntt[i];
		cntb[m - i] += cntb[m + 1 - i];
	}

	REP(i, d)
	{
		if (cl == (cntl[max(sofa[i][0], sofa[i][2]) - 1] - (sofa[i][0] != sofa[i][2]))
			&& cr == (cntr[min(sofa[i][0], sofa[i][2]) + 1] - (sofa[i][0] != sofa[i][2]))
			&& cb == (cntb[min(sofa[i][1], sofa[i][3]) + 1] - (sofa[i][1] != sofa[i][3]))
			&& ct == (cntt[max(sofa[i][1], sofa[i][3]) - 1] - (sofa[i][1] != sofa[i][3]))) {
			cout << i + 1;
			return 0;
		}
	}

	cout << -1;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define task "cf"
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define zs(v) ((int)(v).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define CNTBIT __builtin_popcountll
#define ALL(v) (v).begin(),(v).end()
#define endl '\n'

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;

const int dx[4]={-1, 0, 1, 0}, dy[4]={0, 1, 0, -1};
const int dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1}, dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};

const ll mod=1000000007; /// 998244353
const int base=311;

const int N=1e5+5;

struct segtree
{
    int n;
    vector<int> st;

    segtree (int _n)
    {
        n=_n+5;
        st.assign(4*n+5,0);
    }
    void update(int p, int val, int i, int l, int r)
    {
        if(l==r)
        {
            st[i]+=val;
            return;
        }
        int mid=(l+r)>>1;
        if(p<=mid) update(p,val,i<<1,l,mid);
        else update(p,val,i<<1|1,mid+1,r);
        st[i]=st[i<<1]+st[i<<1|1];
    }
    int get_(int u, int v, int i, int l, int r)
    {
        if(u>r||v<l) return 0;
        if(u<=l&&r<=v) return st[i];
        int mid=(l+r)>>1;
        return get_(u,v,i<<1,l,mid)+get_(u,v,i<<1|1,mid+1,r);
    }
    void upd(int p, int val)
    {
        update(p,val,1,0,n);
    }
    int get(int u, int v)
    {
        return get_(u,v,1,0,n);
    }
};

int d,n,m,cntleft,cntright,cnttop,cntbot;
pii a[N],b[N];

void solve()
{
    cin>>d;
    cin>>n>>m;
    for(int i=1;i<=d;++i)
    {
        cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se;
    }
    cin>>cntleft>>cntright>>cnttop>>cntbot;

    segtree sttop(n),stbot(n),stleft(m),stright(m);

    for(int i=1;i<=d;++i)
    {
        stleft.upd(min(a[i].fi,b[i].fi),1);
        stright.upd(max(a[i].fi,b[i].fi),1);
        sttop.upd(min(a[i].se,b[i].se),1);
        stbot.upd(max(a[i].se,b[i].se),1);
    }

    for(int i=1;i<=d;++i)
    {
        stleft.upd(min(a[i].fi,b[i].fi),-1);
        stright.upd(max(a[i].fi,b[i].fi),-1);
        sttop.upd(min(a[i].se,b[i].se),-1);
        stbot.upd(max(a[i].se,b[i].se),-1);

        int cntl=stleft.get(1,max(a[i].fi,b[i].fi)-1);
        int cntr=stright.get(min(a[i].fi,b[i].fi)+1,n);
        int cntt=sttop.get(1,max(a[i].se,b[i].se)-1);
        int cntb=stbot.get(min(a[i].se,b[i].se)+1,m);

//        cout<<cntl<<' '<<cntr<<' '<<cntt<<' '<<cntb<<endl;

        if(cntl==cntleft&&cntr==cntright&&cntt==cnttop&&cntb==cntbot)
        {
            cout<<i;
            return;
        }

        stleft.upd(min(a[i].fi,b[i].fi),1);
        stright.upd(max(a[i].fi,b[i].fi),1);
        sttop.upd(min(a[i].se,b[i].se),1);
        stbot.upd(max(a[i].se,b[i].se),1);
    }

    cout<<-1;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    solve();
    return 0;
}


#include <iostream>

using namespace std;
int u,r,l,d;
int n,t,t1,t2,t3;
struct s{int x,y,ON;bool r;s *n;}*a[1001][1001];
void verify(s k,int X,int Y)
{
    int x=k->x,y=k->y,ro=k->r;
    for(int i=X-1;i<=X+1;++X)for(int j=Y-1;j<=Y+1;++j)
    {
        s cv=a[i][j];
        while(cv!=)
    }
}
void check1(int X,int Y)
{
    s *kat=a[X][Y];
    while(k!=NULL)
    {
        verify(kat,X,Y);
        kat=kat->n;
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>t>>t1>>t2>>t3;
        s *q=new s;
        q->x=min(t,t2);
        q->y=min(t1,t2);
        if(t1!=t3)q->r=1;
        q->ON=i;
        t=min(t,t2);
        t1=min(t1,t3);
        q->x=t;
        q->y=t1;
        t/=100;
        t1/=100;
        a[t][t1]->n=q;
        q->n=q;
    }
    cin>>l>>r>>u>>d;
    for(int i=1;i<=1000;++i)for(int j=1;j<=1000;++j)check1(i,j);
}


#include <iostream>

using namespace std;
long long N,A,R,L,M;
long long sumdig(long long X)
{
    long long S=0;
    while(X>0)
    {
        S=S+X%10;
        X/=10;
    }
    return S;
}
int main()
{
    cin>>N>>A;
    R=N+1;L=A;
    if(A>=N){cout<<0;return 0;}
    while(R!=L+1)
    {
        M=(R+L)/2;
        if(sumdig(M)>M-A)L=M;
        else R=M;
    }
    cout<<N-R+1;
}


#include<bits/stdc++.h>
using namespace std;

#define iMAX 0x3f3f3f3f
#define llMAX 0x3f3f3f3f3f3f3f3f
#define mem1(array) memset(array, -1, sizeof(array))
#define mem0(array) memset(array, 0, sizeof(array))
#define mem3f(array) memset(array, 3f, sizeof(array))
#define debug(x) printf("%d***", x)
const int maxn = 1e5+7;
vector<int> X[maxn], Y[maxn];
int xx[maxn][4], yy[maxn][4], flag[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int d, n, m;
	cin >> d >> n >> m;
	int x1, y1, x2, y2;
	for(int i = 1; i <= d; i++){
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		xx[i][0] = min(x1, x2), xx[i][1] = max(x1, x2);
		yy[i][0] = min(y1, y2), yy[i][1] = max(y1, y2);
		X[xx[i][0]].push_back(i);
		Y[yy[i][0]].push_back(i);
	}
	int cntl, cntr, cntt, cntb;
	cin >> cntl >> cntr >> cntt >> cntb;
	int sum = 0, aux = 0;
	for(int i = 1; i < maxn; i++) {
		sum += X[i].size();
		if(sum > cntl) {
			if(sum - X[i].size() == cntl) {
				int x_x = 0;
				if(X[i].size() == 1){
					flag[X[i][0]]++;
					x_x = 1;
				}
				else{
					for(int j = 0; j < X[i].size(); j++){
						if(xx[X[i][j]][0] == xx[X[i][j]][1]) flag[X[i][j]]++, x_x++;
					}
					if(sum-X[i].size()+x_x != cntl) return puts("-1"), 0;
				}
				if(d-cntl-x_x != cntr) return puts("-1"), 0;
			}
			else if(sum == cntl + 1) {
				for(int j = 0; j < X[i].size(); j++) {
					if(xx[X[i][j]][0] == xx[X[i][j]][1]) aux++;
					else flag[X[i][j]]++;
				}
				// printf("aux=%d\n", aux);
				if(aux == X[i].size()) break;
				else if(cntr != d - (sum-aux-1)) break;
			}
			//printf("%d---\n", X[i].size());
			break;
		}
	}
	sum = aux = 0;
	for(int i = 1; i < maxn; i++) {
		sum += Y[i].size();
		if(sum > cntt){
			if(sum - Y[i].size() == cntt) {
				int y_y = 0;
				if(Y[i].size() == 1){
					flag[Y[i][0]]++;
					y_y = 1;
				}
				else{
					for(int j = 0; j < Y[i].size(); j++) {
						if(yy[Y[i][j]][0] == yy[Y[i][j]][1]) flag[Y[i][j]]++, y_y++;
					}
					if(sum-Y[i].size()+y_y != cntt) return puts("-1"), 0;
				}
				// debug(y_y);
				if(d-cntt-y_y != cntb) return puts("-1"), 0;
			}
			else if(sum == cntt+1) {
				for(int j = 0; j < Y[i].size(); j++) {
					if(yy[Y[i][j]][0] == yy[Y[i][j]][1]) aux++;
					else flag[Y[i][j]]++;
				}
				if(aux == Y[i].size()) return puts("-1"), 0;
				else if(cntb != d - (sum-aux-1)) return puts("-1"), 0;
			}
			break;
		}
	}

	int res = -1;
	for(int i = 1; i < maxn; i++) if(flag[i] == 2) {
		res = i;
		break;
	}
	cout<<res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define iMAX 0x3f3f3f3f
#define llMAX 0x3f3f3f3f3f3f3f3f
#define mem1(array) memset(array, -1, sizeof(array))
#define mem0(array) memset(array, 0, sizeof(array))
#define mem3f(array) memset(array, 3f, sizeof(array))
#define debug(x) printf("%d***", x)
const int maxn = 1e5+7;
vector<int> X[maxn], Y[maxn];
int xx[maxn][4], yy[maxn][4], flag[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int d, n, m;
	cin >> d >> n >> m;
	int x1, y1, x2, y2;
	for(int i = 1; i <= d; i++){
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		xx[i][0] = min(x1, x2), xx[i][1] = max(x1, x2);
		yy[i][0] = min(y1, y2), yy[i][1] = max(y1, y2);
		X[xx[i][0]].push_back(i);
		Y[yy[i][0]].push_back(i);
	}
	int cntl, cntr, cntt, cntb;
	cin >> cntl >> cntr >> cntt >> cntb;
	int sum = 0, aux = 0;
	for(int i = 1; i < maxn; i++) {
		sum += X[i].size();
		if(sum > cntl) {
			if(sum != cntl + 1) return puts("-1"), 0;
			//printf("%d---\n", X[i].size());
			if(X[i].size() == 1) {
				flag[X[i][0]]++;
				if(cntr != d - sum) return puts("-1"), 0;
			} else {
				for(int j = 0; j < X[i].size(); j++) {
					if(xx[X[i][j]][0] == xx[X[i][j]][1]) aux++;
					else flag[X[i][j]]++;
				}
				//printf("aux=%d\n", aux);
				if(aux == X[i].size()) return puts("-1"), 0;
				else if(cntr != d - (sum-aux-1)) return puts("-1"), 0;
			}
			break;
		}
	}
	sum = aux = 0;
	for(int i = 1; i < maxn; i++) {
		sum += Y[i].size();
		if(sum >= cntt+1) {
			if(sum != cntt + 1) return puts("-1"), 0;
			if(Y[i].size() == 1) {
				flag[Y[i][0]]++;
				if(cntb != d - sum) return puts("-1"), 0;
			} else {
				for(int j = 0; j < Y[i].size(); j++) {
					if(yy[Y[i][j]][0] == yy[Y[i][j]][1]) aux++;
					else flag[Y[i][j]]++;
				}
				if(aux == Y[i].size()) return puts("-1"), 0;
				else if(cntb != d - (sum-aux-1)) return puts("-1"), 0;
			}
			break;
		}
	}
	int res = -1;
	for(int i = 1; i < maxn; i++) if(flag[i] == 2) {
		res = i;
		break;
	}
	cout<<res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define iMAX 0x3f3f3f3f
#define llMAX 0x3f3f3f3f3f3f3f3f
#define mem1(array) memset(array, -1, sizeof(array))
#define mem0(array) memset(array, 0, sizeof(array))
#define mem3f(array) memset(array, 3f, sizeof(array))
#define debug(x) printf("%d***", x)
const int maxn = 1e5+7;
vector<int> X[maxn], Y[maxn];
int xx[maxn][4], yy[maxn][4], flag[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int d, n, m;
	cin >> d >> n >> m;
	int x1, y1, x2, y2;
	for(int i = 1; i <= d; i++){
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		xx[i][0] = min(x1, x2), xx[i][1] = max(x1, x2);
		yy[i][0] = min(y1, y2), yy[i][1] = max(y1, y2);
		X[xx[i][0]].push_back(i);
		Y[yy[i][0]].push_back(i);
	}
	int cntl, cntr, cntt, cntb;
	cin >> cntl >> cntr >> cntt >> cntb;
	int sum = 0, aux = 0;
	for(int i = 1; i < maxn; i++) {
		sum += X[i].size();
		if(sum > cntl) {
			if(sum - X[i].size() == cntl) {
				int x_x = 0;
				if(X[i].size() == 1){
					flag[X[i][0]]++;
					x_x = 1;
				}
				else{
					for(int j = 0; j < X[i].size(); j++){
						if(xx[X[i][j]][0] == xx[X[i][j]][1]) flag[X[i][j]]++, x_x++;
					}
					if(!x_x) return puts("-1"), 0;
				}
				if(d-cntl-x_x != cntr) return puts("-1"), 0;
			}
			else if(sum == cntl + 1) {
				for(int j = 0; j < X[i].size(); j++) {
					if(xx[X[i][j]][0] == xx[X[i][j]][1]) aux++;
					else flag[X[i][j]]++;
				}
				// printf("aux=%d\n", aux);
				if(aux == X[i].size()) return puts("-1"), 0;
				else if(cntr != d - (sum-X[i].size()+aux+1)) return puts("-1"), 0;
			}
			//printf("%d---\n", X[i].size());
			break;
		}
	}
	sum = aux = 0;
	for(int i = 1; i < maxn; i++) {
		sum += Y[i].size();
		if(sum > cntt){
			if(sum - Y[i].size() == cntt) {
				int y_y = 0;
				if(Y[i].size() == 1){
					flag[Y[i][0]]++;
					y_y = 1;
				}
				else{
					for(int j = 0; j < Y[i].size(); j++) {
						if(yy[Y[i][j]][0] == yy[Y[i][j]][1]) flag[Y[i][j]]++, y_y++;
					}
					if(!y_y) return puts("-1"), 0;
				}
				// debug(y_y);
				if(d-cntt-y_y != cntb) return puts("-1"), 0;
			}
			else if(sum == cntt+1) {
				for(int j = 0; j < Y[i].size(); j++) {
					if(yy[Y[i][j]][0] == yy[Y[i][j]][1]) aux++;
					else flag[Y[i][j]]++;
				}
				if(aux == Y[i].size()) return puts("-1"), 0;
				else if(cntb != d - (sum-Y[i].size()+aux+1)) return puts("-1"), 0;
			}
			break;
		}
	}

	int res = -1;
	for(int i = 1; i < maxn; i++) if(flag[i] == 2) {
		res = i;
		break;
	}
	cout<<res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define iMAX 0x3f3f3f3f
#define llMAX 0x3f3f3f3f3f3f3f3f
#define mem1(array) memset(array, -1, sizeof(array))
#define mem0(array) memset(array, 0, sizeof(array))
#define mem3f(array) memset(array, 3f, sizeof(array))
#define debug(x) printf("%d***", x)
const int maxn = 1e5+7;
vector<int> X[maxn], Y[maxn];
int xx[maxn][4], yy[maxn][4], flag[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int d, n, m;
	cin >> d >> n >> m;
	int x1, y1, x2, y2;
	for(int i = 1; i <= d; i++){
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		xx[i][0] = min(x1, x2), xx[i][1] = max(x1, x2);
		yy[i][0] = min(y1, y2), yy[i][1] = max(y1, y2);
		X[xx[i][0]].push_back(i);
		Y[yy[i][0]].push_back(i);
	}
	int cntl, cntr, cntt, cntb;
	cin >> cntl >> cntr >> cntt >> cntb;
	int sum = 0, aux = 0;
	for(int i = 1; i < maxn; i++) {
		sum += X[i].size();
		if(sum > cntl) {
			if(sum - X[i].size() == cntl) {
				int x_x = 0;
				if(X[i].size() == 1){
					flag[X[i][0]]++;
					x_x = 1;
				}
				else{
					for(int j = 0; j < X[i].size(); j++){
						if(xx[X[i][j]][0] == xx[X[i][j]][1]) flag[X[i][j]]++, x_x++;
					}
					if(!x_x) return puts("-1"), 0;
				}
				if(d-cntl-x_x != cntr) return puts("-1"), 0;
			}
			else if(sum == cntl + 1) {
				for(int j = 0; j < X[i].size(); j++) {
					if(xx[X[i][j]][0] == xx[X[i][j]][1]) aux++;
					else flag[X[i][j]]++;
				}
				// printf("aux=%d\n", aux);
				if(aux == X[i].size()) break;
				else if(cntr != d - (sum-aux-1)) break;
			}
			//printf("%d---\n", X[i].size());
			break;
		}
	}
	sum = aux = 0;
	for(int i = 1; i < maxn; i++) {
		sum += Y[i].size();
		if(sum > cntt){
			if(sum - Y[i].size() == cntt) {
				int y_y = 0;
				if(Y[i].size() == 1){
					flag[Y[i][0]]++;
					y_y = 1;
				}
				else{
					for(int j = 0; j < Y[i].size(); j++) {
						if(yy[Y[i][j]][0] == yy[Y[i][j]][1]) flag[Y[i][j]]++, y_y++;
					}
					if(!y_y) return puts("-1"), 0;
				}
				// debug(y_y);
				if(d-cntt-y_y != cntb) return puts("-1"), 0;
			}
			else if(sum == cntt+1) {
				for(int j = 0; j < Y[i].size(); j++) {
					if(yy[Y[i][j]][0] == yy[Y[i][j]][1]) aux++;
					else flag[Y[i][j]]++;
				}
				if(aux == Y[i].size()) return puts("-1"), 0;
				else if(cntb != d - (sum-aux-1)) return puts("-1"), 0;
			}
			break;
		}
	}

	int res = -1;
	for(int i = 1; i < maxn; i++) if(flag[i] == 2) {
		res = i;
		break;
	}
	cout<<res;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod 1000000007
#define pi 3.14159265358979323
using namespace std;
typedef pair<int,int> ii;
pair<ii,ii> p[100005];
//int tree1[8000002];
//
//void add(int node,int L,int R,int indx,int val)
//{
//    if(L == R)
//    {
//        tree1[node] += val;
//        return ;
//    }
//    int mid = (L+R)/2;
//
//    if(indx >= L && indx <= mid)
//        add(2*node,L,mid,indx,val);
//    else
//        add(2*node+1,mid+1,R,indx,val);
//    tree1[node] = tree1[2*node] + tree1[2*node+1];
//}
//
//int query(int node,int L,int R ,int l,int r)
//{
//    if( L > R || L < r || R < l)
//        return 0;
//    if( L >= l && R <= r)
//        return tree1[node];
//
//    int mid = (L+R)/2;
//
//    return query(2*node,L,mid,l,r) + query(2*node,L,mid,l,r);
//}

int main()
{
    vector<int> my1,my2,my3,my4;
    int d;
    cin >> d;
    int n,m;
    cin >> n >> m;
    for(int i=0; i<d; i++)
    {
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        p[i] = {{x1,y1},{x2,y2}};
        my1.push_back(min(x1,x2));
        my3.push_back(max(x1,x2));
        my2.push_back(min(y1,y2));
        my4.push_back(max(y1,y2));
    }
    sort(All(my1));
    sort(All(my2));
    int cnt[4];
    for(int i=0; i<4; i++)
        cin >> cnt[i];

    for(int i=0; i<d; i++)
    {
        int k[4] = {};

        int mn1 = min(p[i].F.F,p[i].S.F),mx1 = max(p[i].F.F,p[i].S.F);
        int mn2 = min(p[i].F.S,p[i].S.S),mx2 = max(p[i].F.S,p[i].S.S);

        int x1 = lower_bound(All(my1),mx1) - my1.begin();

        if(mn1 != mx1) x1--;
        k[0] += x1;

        x1 = d-(upper_bound(All(my3),mn1)-my3.begin());
        if(mn1 != mx1)x1--;
        k[1] += x1;

        x1 = lower_bound(All(my2),mx2) - my2.begin();
        if(mn2 != mx2) x1--;
        k[3] += x1;

        x1 = d-(upper_bound(All(my4),mn2)-my4.begin());
        if(mn2 != mx2) x1--;
        k[2] += x1;

      //  cout << "::: " << k[0] << " " << k[1] << " " << k[3] << " " << k[2] << endl;

        if(k[0] == cnt[0] && k[1] == cnt[1] && k[3] == cnt[2] && k[2] == cnt[3])
        {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod 1000000007
#define pi 3.14159265358979323
using namespace std;
typedef pair<int,int> ii;
pair<ii,ii> p[100005];
//int tree1[8000002];
//
//void add(int node,int L,int R,int indx,int val)
//{
//    if(L == R)
//    {
//        tree1[node] += val;
//        return ;
//    }
//    int mid = (L+R)/2;
//
//    if(indx >= L && indx <= mid)
//        add(2*node,L,mid,indx,val);
//    else
//        add(2*node+1,mid+1,R,indx,val);
//    tree1[node] = tree1[2*node] + tree1[2*node+1];
//}
//
//int query(int node,int L,int R ,int l,int r)
//{
//    if( L > R || L < r || R < l)
//        return 0;
//    if( L >= l && R <= r)
//        return tree1[node];
//
//    int mid = (L+R)/2;
//
//    return query(2*node,L,mid,l,r) + query(2*node,L,mid,l,r);
//}

int main()
{
    vector<int> my1,my2,my3,my4;
    int d;
    cin >> d;
    int n,m;
    cin >> n >> m;
    for(int i=0; i<d; i++)
    {
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        p[i] = {{x1,y1},{x2,y2}};
        my1.push_back(min(x1,x2));
        my3.push_back(max(x1,x2));
        my2.push_back(min(y1,y2));
        my4.push_back(max(y1,y2));
    }
    sort(All(my1));
    sort(All(my2));
    sort(All(my3));
    sort(All(my4));
    int cnt[4];
    for(int i=0; i<4; i++)
        cin >> cnt[i];

    for(int i=0; i<d; i++)
    {
        int k[4] = {};

        int mn1 = min(p[i].F.F,p[i].S.F),mx1 = max(p[i].F.F,p[i].S.F);
        int mn2 = min(p[i].F.S,p[i].S.S),mx2 = max(p[i].F.S,p[i].S.S);

        int x1 = lower_bound(All(my1),mx1) - my1.begin();

        if(mn1 != mx1) x1--;
        k[0] += x1;

        x1 = d-(upper_bound(All(my3),mn1)-my3.begin());
        if(mn1 != mx1)x1--;
        k[1] += x1;

        x1 = lower_bound(All(my2),mx2) - my2.begin();
        if(mn2 != mx2) x1--;
        k[3] += x1;

        x1 = d-(upper_bound(All(my4),mn2)-my4.begin());

//        if(i == 2)
//            cout << x1 << " " << mn2 << " " << mx2  << " "  << my4.size() << endl;
        if(mn2 != mx2) x1--;
        k[2] += x1;

     //   cout << "::: " << k[0] << " " << k[1] << " " << k[3] << " " << k[2] << endl;

        if(k[0] == cnt[0] && k[1] == cnt[1] && k[3] == cnt[2] && k[2] == cnt[3])
        {
            cout << i+1 << endl;
            //return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod 1000000007
#define pi 3.14159265358979323
using namespace std;
typedef pair<int,int> ii;
pair<ii,ii> p[100005];
//int tree1[8000002];
//
//void add(int node,int L,int R,int indx,int val)
//{
//    if(L == R)
//    {
//        tree1[node] += val;
//        return ;
//    }
//    int mid = (L+R)/2;
//
//    if(indx >= L && indx <= mid)
//        add(2*node,L,mid,indx,val);
//    else
//        add(2*node+1,mid+1,R,indx,val);
//    tree1[node] = tree1[2*node] + tree1[2*node+1];
//}
//
//int query(int node,int L,int R ,int l,int r)
//{
//    if( L > R || L < r || R < l)
//        return 0;
//    if( L >= l && R <= r)
//        return tree1[node];
//
//    int mid = (L+R)/2;
//
//    return query(2*node,L,mid,l,r) + query(2*node,L,mid,l,r);
//}

int main()
{
    vector<int> my1,my2,my3,my4;
    int d;
    cin >> d;
    int n,m;
    cin >> n >> m;
    for(int i=0; i<d; i++)
    {
        int x1,y1,x2,y2;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        p[i] = {{x1,y1},{x2,y2}};
        my1.push_back(min(x1,x2));
        my3.push_back(max(x1,x2));
        my2.push_back(min(y1,y2));
        my4.push_back(max(y1,y2));
    }
    sort(All(my1));
    sort(All(my2));
    sort(All(my3));
    sort(All(my4));
    int cnt[4];
    for(int i=0; i<4; i++)
        cin >> cnt[i];

    for(int i=0; i<d; i++)
    {
        int k[4] = {};

        int mn1 = min(p[i].F.F,p[i].S.F),mx1 = max(p[i].F.F,p[i].S.F);
        int mn2 = min(p[i].F.S,p[i].S.S),mx2 = max(p[i].F.S,p[i].S.S);

        int x1 = lower_bound(All(my1),mx1) - my1.begin();

        if(mn1 != mx1) x1--;
        k[0] += x1;

        x1 = d-(upper_bound(All(my3),mn1)-my3.begin());
        if(mn1 != mx1)x1--;
        k[1] += x1;

        x1 = lower_bound(All(my2),mx2) - my2.begin();
        if(mn2 != mx2) x1--;
        k[3] += x1;

        x1 = d-(upper_bound(All(my4),mn2)-my4.begin());

//        if(i == 2)
//            cout << x1 << " " << mn2 << " " << mx2  << " "  << my4.size() << endl;
        if(mn2 != mx2) x1--;
        k[2] += x1;

     //   cout << "::: " << k[0] << " " << k[1] << " " << k[3] << " " << k[2] << endl;

        if(k[0] == cnt[0] && k[1] == cnt[1] && k[3] == cnt[2] && k[2] == cnt[3])
        {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long  LL;
const int N = 1e5 + 24;
const LL MOD =   1000000007;
struct point{
	int id,x,y;
}s[N*2];
struct node{
	int l,r,t,b;
}ans[N],p;
int d,n,m;
int jd[N];
int num[N];
bool cmpl(const point x, const point y){
	return x.x <  y.x;
}
bool cmpr(const point x, const point y){
	return x.x >  y.x;
}
bool cmpt(const point x, const point y){
	return x.y <  y.y;
}
bool cmpb(const point x, const point y){
	return x.y >  y.y;
}
bool cmpid(const point x, const point y){
	return x.id <  y.id;
}
void solve(int x){
	memset(jd,0,sizeof(jd));
	memset(num,0,sizeof(num));
	int last = -1;
	for(int i = 0; i < d; i++){
		if(x == 0){
			if(s[i].x != s[i-1].x && i > 0){
				last = i-1;
			}
			ans[s[i].id].l = num[last+1];
		}
		else if(x == 1){
			if(s[i].x != s[i-1].x && i > 0){
				last = i-1;
			}
			ans[s[i].id].r = num[last+1];
			//printf("%d %d %d %d\n",s[i].id,s[i].x,last,num[last+1]);
		}
		else if(x == 2){
			if(s[i].y != s[i-1].y && i > 0){
				last = i-1;
			}
			ans[s[i].id].t = num[last+1];
		}
		else if(x == 3){
			if(s[i].y != s[i-1].y && i > 0){
				last = i-1;
			}
			ans[s[i].id].b = num[last+1];
		}
		if(!jd[s[i].id]){
			jd[s[i].id] = 1;
			num[i+1] = num[i] + 1;
		}
		else{
			num[i+1] = num[i];
		}
	}
}
int main()
{
#ifdef CDZSC_OFFLINE
	freopen("in.txt","r",stdin);
#endif //CDZSC_OFFLINE
	while(~scanf("%d",&d))
	{
		scanf("%d%d",&n,&m);
		for(int i = 0; i < d; i++){
			scanf("%d%d%d%d\n",&s[i*2].x,&s[i*2].y,&s[i*2+1].x,&s[i*2+1].y);
			s[i*2].id = i;
			s[i*2+1].id = i;
		}
		scanf("%d%d%d%d",&p.l,&p.r,&p.t,&p.b);
		d *= 2;
		sort(s,s+d,cmpl);
		solve(0);
		sort(s,s+d,cmpr);
		solve(1);
		sort(s,s+d,cmpt);
		solve(2);
		sort(s,s+d,cmpb);
		solve(3);
		sort(s,s+d,cmpid);
		for(int i = 0; i < d; i+=2){
			if(s[i].x != s[i+1].x){
				ans[i/2].l--;
				ans[i/2].r--;
			}
			if(s[i].y != s[i+1].y){
				ans[i/2].t--;
				ans[i/2].b--;
			}
		}
		int ansnum = -1;
		for(int i = 0; i < d / 2; i++){
			//printf("*%d %d %d %d\n",ans[i].l,ans[i].r,ans[i].t,ans[i].b);
			if(ans[i].l == p.l && ans[i].r == p.r && ans[i].t == p.t && ans[i].b == p.b){
				if(ansnum == -1)
					ansnum = i+1;
				else{
					ansnum = -1;
					break;
				}
			}
		}
		printf("%d\n",ansnum);
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long  LL;
const int N = 1e5 + 24;
const LL MOD =   1000000007;
struct point{
	int id,x,y;
}s[N*2];
struct node{
	int l,r,t,b;
}ans[N],p;
int d,n,m;
int jd[N];
bool cmpl(const point x, const point y){
	return x.x <  y.x;
}
bool cmpr(const point x, const point y){
	return x.x >  y.x;
}
bool cmpt(const point x, const point y){
	return x.y <  y.y;
}
bool cmpb(const point x, const point y){
	return x.y >  y.y;
}
void solve(int x){
	memset(jd,0,sizeof(jd));
	int num = 0;
	for(int i = 0; i < d; i++){
		if(x == 0){
			if(jd[s[i].id])
				ans[s[i].id].l = num - 1;
			else
				ans[s[i].id].l = num;
		}
		else if(x == 1){
			if(jd[s[i].id])
				ans[s[i].id].r = num - 1;
			else
				ans[s[i].id].r = num;
		}
		else if(x == 2){
			if(jd[s[i].id])
				ans[s[i].id].t = num - 1;
			else
				ans[s[i].id].t = num;
		}
		else if(x == 3){
			if(jd[s[i].id])
				ans[s[i].id].b = num - 1;
			else
				ans[s[i].id].b = num;
		}
		if(!jd[s[i].id]){
			jd[s[i].id] = 1;
			num++;
		}
	}
}
int main()
{
#ifdef CDZSC_OFFLINE
	freopen("in.txt","r",stdin);
#endif //CDZSC_OFFLINE
	while(~scanf("%d",&d))
	{
		scanf("%d%d",&n,&m);
		for(int i = 0; i < d; i++){
			scanf("%d%d%d%d\n",&s[i*2].x,&s[i*2].y,&s[i*2+1].x,&s[i*2+1].y);
			s[i*2].id = i;
			s[i*2+1].id = i;
		}
		scanf("%d%d%d%d",&p.l,&p.r,&p.t,&p.b);
		d *= 2;
		sort(s,s+d,cmpl);
		solve(0);
		sort(s,s+d,cmpr);
		solve(1);
		sort(s,s+d,cmpt);
		solve(2);
		sort(s,s+d,cmpb);
		solve(3);
		int ansnum = -1;
		for(int i = 0; i < d / 2; i++){
			//printf("%d %d %d %d\n",ans[i].l,ans[i].r,ans[i].t,ans[i].b);
			if(ans[i].l == p.l && ans[i].r == p.r && ans[i].t == p.t && ans[i].b == p.b){
				if(ansnum == -1)
					ansnum = i+1;
				else{
					ansnum = -1;
					break;
				}
			}
		}
		printf("%d\n",ansnum);
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long  LL;
const int N = 2 * 1e5 + 24;
const LL MOD =   1000000007;
struct point{
	int id,x,y;
}s[N];
struct node{
	int l,r,t,b;
}ans[N],p;
int d,n,m;
int jd[N];
int num[N];
bool cmpl(const point x, const point y){
	return x.x <  y.x;
}
bool cmpr(const point x, const point y){
	return x.x >  y.x;
}
bool cmpt(const point x, const point y){
	return x.y <  y.y;
}
bool cmpb(const point x, const point y){
	return x.y >  y.y;
}
bool cmpid(const point x, const point y){
	return x.id <  y.id;
}
void solve(int x){
	memset(jd,0,sizeof(jd));
	memset(num,0,sizeof(num));
	int last = -1;
	for(int i = 0; i < d; i++){
		if(x == 0){
			if(s[i].x != s[i-1].x && i > 0){
				last = i-1;
			}
			ans[s[i].id].l = num[last+1];
		}
		else if(x == 1){
			if(s[i].x != s[i-1].x && i > 0){
				last = i-1;
			}
			ans[s[i].id].r = num[last+1];
			//printf("%d %d %d %d\n",s[i].id,s[i].x,last,num[last+1]);
		}
		else if(x == 2){
			if(s[i].y != s[i-1].y && i > 0){
				last = i-1;
			}
			ans[s[i].id].t = num[last+1];
		}
		else if(x == 3){
			if(s[i].y != s[i-1].y && i > 0){
				last = i-1;
			}
			ans[s[i].id].b = num[last+1];
		}
		if(!jd[s[i].id]){
			jd[s[i].id] = 1;
			num[i+1] = num[i] + 1;
		}
		else{
			num[i+1] = num[i];
		}
	}
}
int main()
{
#ifdef CDZSC_OFFLINE
	freopen("in.txt","r",stdin);
#endif //CDZSC_OFFLINE
	while(~scanf("%d",&d))
	{
		scanf("%d%d",&n,&m);
		for(int i = 0; i < d; i++){
			scanf("%d%d%d%d\n",&s[i*2].x,&s[i*2].y,&s[i*2+1].x,&s[i*2+1].y);
			s[i*2].id = i;
			s[i*2+1].id = i;
		}
		scanf("%d%d%d%d",&p.l,&p.r,&p.t,&p.b);
		d *= 2;
		sort(s,s+d,cmpl);
		solve(0);
		sort(s,s+d,cmpr);
		solve(1);
		sort(s,s+d,cmpt);
		solve(2);
		sort(s,s+d,cmpb);
		solve(3);
		sort(s,s+d,cmpid);
		for(int i = 0; i < d; i+=2){
			if(s[i].x != s[i+1].x){
				ans[i/2].l--;
				ans[i/2].r--;
			}
			if(s[i].y != s[i+1].y){
				ans[i/2].t--;
				ans[i/2].b--;
			}
		}
		int ansnum = -1;
		for(int i = 0; i < d / 2; i++){
			if(ans[i].l == p.l && ans[i].r == p.r && ans[i].t == p.t && ans[i].b == p.b){
				if(ansnum == -1)
					ansnum = i+1;
				else{
					ansnum = -1;
					break;
				}
			}
		}
		printf("%d\n",ansnum);
	}
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <stack>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <tuple>
using namespace std;

int d;
int n, m;
vector<tuple<int, int, int, int> > sofa;
vector<int> l, r, t, b;
int c[4];
int bx = 0;

void read_data() {
	cin >> d;
	cin >> n >> m;
	sofa.reserve(d);
	for (int i = 0; i < d; i++) {
		int x1, y1, x2, y2;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		sofa.emplace_back(x1, y1, x2, y2);
	}
	for (int i = 0; i < 4; i++) cin >> c[i];
}

int getv(int i) {
	if (i < d) {
		if (bx == 0)
			return get<0>(sofa[i]);
		else
			return get<1>(sofa[i]);
	} else {
		i -= d;
		if (bx == 0)
			return get<2>(sofa[i]);
		else
			return get<3>(sofa[i]);
	}
}

int cmp(const int &i, const int &j) {
	int a, b;
	a = getv(i);
	b = getv(j);
	return a < b;
}

void deal(vector<int> &lc, vector<int> &rc) {
	lc.resize(d);
	rc.resize(d);
	vector<int> a;
	for (int i = 0; i < d; i++) {
		a.push_back(i);
		a.push_back(i+d);
	}
	sort(a.begin(), a.end(), cmp);
	vector<int> isv;
	isv.assign(d, 2);
	int zero_cnt = 0;
	int one_cnt = 0;
	int pk = 0;
	while (pk < d+d) {
		int l= 1;
		int v = getv(a[pk]);
		for (l = 2; ; l++) {
			if (pk+l == d+d) {
				break;
			}
			if (getv(a[pk+l-1]) != v) {
				break;
			}
		}
		l--;
		for (int k = 0; k < l; k++) {
			int i = a[pk+k];
			if (i >= d) i -=d;
			lc[i] = max(lc[i], zero_cnt + one_cnt - (isv[i] == 1));
		}
		for (int k = 0; k < l; k++) {
			int i = a[pk+k];
			if (i >= d) i -= d;
			if (isv[i] == 2) {
				one_cnt++;
			} else if (isv[i] == 1) {
				one_cnt--;
				zero_cnt++;
			}
			isv[i]--;
		}
		int two_cnt = d - zero_cnt - one_cnt;
		for (int k = 0; k < l; k++) {
			int i = a[pk+k];
			if (i >= d) i -= d;
			rc[i] = max(rc[i], two_cnt + one_cnt - (isv[i] == 1));
		}
		pk = pk + l;
	}
}

int main() {
	read_data();
	bx = 0;
	deal(l, r);
	bx = 1;
	deal(t, b);
	int cnt = -1;
	for (int i = 0; i < d; i++) {
		if (l[i] == c[0] && r[i] == c[1] && t[i] == c[2] && b[i] == c[3]) {
			cnt = i+1;
		}
	}
	cout << cnt << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <stack>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <tuple>
using namespace std;

int d;
int n, m;
vector<tuple<int, int, int, int> > sofa;
vector<int> l, r, t, b;
int c[4];
int bx = 0;

void read_data() {
	cin >> d;
	cin >> n >> m;
	sofa.reserve(d);
	for (int i = 0; i < d; i++) {
		int x1, y1, x2, y2;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		sofa.emplace_back(x1, y1, x2, y2);
	}
	for (int i = 0; i < 4; i++) cin >> c[i];
}

int getv(int i) {
	if (i < d) {
		if (bx == 0)
			return get<0>(sofa[i]);
		else
			return get<1>(sofa[i]);
	} else {
		i -= d;
		if (bx == 0)
			return get<2>(sofa[i]);
		else
			return get<3>(sofa[i]);
	}
}

int cmp(const int &i, const int &j) {
	int a, b;
	a = getv(i);
	b = getv(j);
	return a < b;
}

void deal(vector<int> &lc, vector<int> &rc) {
	lc.resize(d);
	rc.resize(d);
	vector<int> a;
	for (int i = 0; i < d; i++) {
		a.push_back(i);
		a.push_back(i+d);
	}
	sort(a.begin(), a.end(), cmp);
	vector<int> isv;
	isv.assign(d, 2);
	int zero_cnt = 0;
	int one_cnt = 0;
	int pk = 0;
	while (pk < d+d) {
		int l= 1;
		int v = getv(a[pk]);
		for (l = 2; ; l++) {
			if (pk+l > d+d) {
				break;
			}
			if (getv(a[pk+l-1]) != v) {
				break;
			}
		}
		l--;
		for (int k = 0; k < l; k++) {
			int i = a[pk+k];
			if (i >= d) i -=d;
			lc[i] = max(lc[i], zero_cnt + one_cnt - (isv[i] == 1));
		}
		for (int k = 0; k < l; k++) {
			int i = a[pk+k];
			if (i >= d) i -= d;
			if (isv[i] == 2) {
				one_cnt++;
			} else if (isv[i] == 1) {
				one_cnt--;
				zero_cnt++;
			}
			isv[i]--;
		}
		int two_cnt = d - zero_cnt - one_cnt;
		for (int k = 0; k < l; k++) {
			int i = a[pk+k];
			if (i >= d) i -= d;
			rc[i] = max(rc[i], two_cnt + one_cnt - (isv[i] == 1));
		}
		pk = pk + l;
	}
}

int main() {
	read_data();
	bx = 0;
	deal(l, r);
	bx = 1;
	deal(t, b);
	int cnt = -1;
	for (int i = 0; i < d; i++) {
		if (l[i] == c[0] && r[i] == c[1] && t[i] == c[2] && b[i] == c[3]) {
			cnt = i+1;
		}
	}
	cout << cnt << endl;
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <climits>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#define INF 0x3f3f3f3f
#define LL long long
#define fora(i,a,n) for(int i=a;i<=n;i++)
#define fors(i,n,a) for(int i=n;i>=a;i--)
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define MAXN 100024
const double eps = 1e-8;
using namespace std;
int d, n, m;
int T[MAXN], L[MAXN], R[MAXN], B[MAXN];
int cntl = 0, cntr = 0, cntt = 0, cntb = 0;
struct P {
	int x1, x2, y1, y2;
	P(int _x1, int _y1, int _x2, int _y2) {
		x1 = _x1; y1 = _y1; x2 = _x2; y2 = _y2;
	}
	P() {}

}p[10];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#endif
	cin >> d >> n >> m;
	memset(T, 0, sizeof(T));
	memset(B, 0, sizeof(B));
	memset(L, 0, sizeof(L));
	memset(R, 0, sizeof(R));
	int x1, y1, x2, y2;
	for (int i = 0; i<d; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		p[i] = P(x1, y1, x2, y2);
		int ml = min(x1, x2), mr = max(x1, x2);
		int mt = min(y1, y2), mb = max(y1, y2);
		//	printf("%d %d %d %d\n", ml, mr, mt, mb);
		L[ml + 1]++; R[mr - 1]++;  T[mt + 1]++; B[mb - 1]++;
	}
	for (int i = 2; i <= n; i++)
		L[i] += L[i - 1], T[i] += T[i - 1];
	for (int i = n-1; i >= 1; i--)
		R[i] += R[i + 1], B[i] += B[i + 1];
	scanf("%d%d%d%d", &cntl, &cntr, &cntt, &cntb);

	int sum = 0;
	for (int i = 0; i<d; i++) {
		int ml = max(p[i].x1, p[i].x2), mr = min(p[i].x1, p[i].x2);
		int mt = max(p[i].y1, p[i].y2), mb = min(p[i].y1, p[i].y2);

		int numl = L[ml], numr = R[mr], numt = T[mt], numb = B[mb];
		if (p[i].x1 != p[i].x2) numl--, numr--;
		else numt--, numb--;

		//	printf("\n%d %d %d %d\n", ml, mr, mt, mb);
		//	printf("%d %d %d %d\n\n", numl, numr, numt, numb);

		if (numl == cntl&&numr == cntr&&numt == cntt
			&&numb == cntb) sum = i + 1;

	}
	if (sum == 0) printf("-1");
	else printf("%d", sum);
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <climits>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#define INF 0x3f3f3f3f
#define LL long long
#define fora(i,a,n) for(int i=a;i<=n;i++)
#define fors(i,n,a) for(int i=n;i>=a;i--)
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define MAXN 100024
const double eps = 1e-8;
using namespace std;
int d, n, m;
int T[MAXN], L[MAXN], R[MAXN], B[MAXN];
int cntl = 0, cntr = 0, cntt = 0, cntb = 0;
struct P {
	int x1, x2, y1, y2;
	P(int _x1, int _y1, int _x2, int _y2) {
		x1 = _x1; y1 = _y1; x2 = _x2; y2 = _y2;
	}
	P() {}

}p[MAXN];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#endif
	scanf("%d%d%d", &d, &n, &m);
	memset(T, 0, sizeof(T));
	memset(B, 0, sizeof(B));
	memset(L, 0, sizeof(L));
	memset(R, 0, sizeof(R));
	int x1, y1, x2, y2;
	for (int i = 0; i<d; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		p[i] = P(x1, y1, x2, y2);
		int ml = min(x1, x2), mr = max(x1, x2);
		int mt = min(y1, y2), mb = max(y1, y2);
		//	printf("%d %d %d %d\n", ml, mr, mt, mb);
		L[ml + 1]++; R[mr - 1]++;  T[mt + 1]++; B[mb - 1]++;
	}
	for (int i = 2; i <= n; i++)	L[i] += L[i - 1];
	for(int i=2;i<=m;i++)		T[i] += T[i - 1];
	for (int i = n - 1; i >= 1; i--)R[i] += R[i + 1];
	for (int i = m - 1; i >= 1; i--) B[i] += B[i + 1];
	scanf("%d%d%d%d", &cntl, &cntr, &cntt, &cntb);

	int sum = 0;
	for (int i = 0; i<d; i++) {
		int ml = min(p[i].x1, p[i].x2), mr = max(p[i].x1, p[i].x2);
		int mt = min(p[i].y1, p[i].y2), mb = max(p[i].y1, p[i].y2);

		int numl = L[mr], numr = R[ml], numt = T[mb], numb = B[mt];
		if (p[i].x1 != p[i].x2) numl--, numr--;
		else numt--, numb--;

		//	printf("\n%d %d %d %d\n", ml, mr, mt, mb);
	//		printf("%d %d %d %d\n\n", numl, numr, numt, numb);

		if (numl == cntl&&numr == cntr&&numt == cntt
			&&numb == cntb) sum = i + 1;

	}
	if (sum == 0) printf("-1");
	else printf("%d", sum);
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <climits>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#define INF 0x3f3f3f3f
#define LL long long
#define fora(i,a,n) for(int i=a;i<=n;i++)
#define fors(i,n,a) for(int i=n;i>=a;i--)
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define MAXN 100024
const double eps = 1e-8;
using namespace std;
int d, n, m;
int T[MAXN], L[MAXN], R[MAXN], B[MAXN];
int cntl = 0, cntr = 0, cntt = 0, cntb = 0;
struct P {
	int x1, x2, y1, y2;
	P(int _x1, int _y1, int _x2, int _y2) {
		x1 = _x1; y1 = _y1; x2 = _x2; y2 = _y2;
	}
	P() {}

}p[10];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#endif
	cin >> d >> n >> m;
	memset(T, 0, sizeof(T));
	memset(B, 0, sizeof(B));
	memset(L, 0, sizeof(L));
	memset(R, 0, sizeof(R));
	int x1, y1, x2, y2;
	for (int i = 0; i<d; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		p[i] = P(x1, y1, x2, y2);
		int ml = max(x1, x2), mr = min(x1, x2);
		int mt = max(y1, y2), mb = min(y1, y2);
	//	printf("%d %d %d %d\n", ml, mr, mt, mb);
		for (int i = 1; i<ml; i++)
			R[i]++;
		for (int i = mr + 1; i <= n; i++)
			L[i]++;
		for (int i = 1; i<mt; i++)
			B[i]++;
		for (int i = mb + 1; i <= m; i++)
			T[i]++;

	}
	scanf("%d%d%d%d", &cntl, &cntr, &cntt, &cntb);
	int sum = 0;
	for (int i = 0; i<d; i++) {
		int ml = max(p[i].x1, p[i].x2), mr = min(p[i].x1, p[i].x2);
		int mt = max(p[i].y1, p[i].y2), mb = min(p[i].y1, p[i].y2);

		int numl = L[ml ], numr = R[mr], numt = T[mt ], numb = B[mb ];
		if (p[i].x1 != p[i].x2) numl--, numr--;
		else numt--, numb--;

	//	printf("\n%d %d %d %d\n", ml, mr, mt, mb);
	//	printf("%d %d %d %d\n\n", numl, numr, numt, numb);

		if (numl == cntl&&numr == cntr&&numt == cntt
			&&numb == cntb) sum = i + 1;

	}
	if (sum == 0) printf("-1");
	else printf("%d", sum);
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <climits>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#define INF 0x3f3f3f3f
#define LL long long
#define fora(i,a,n) for(int i=a;i<=n;i++)
#define fors(i,n,a) for(int i=n;i>=a;i--)
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define MAXN 100024
const double eps = 1e-8;
using namespace std;
int d, n, m;
int T[MAXN], L[MAXN], R[MAXN], B[MAXN];
int cntl = 0, cntr = 0, cntt = 0, cntb = 0;
struct P {
	int x1, x2, y1, y2;
	P(int _x1, int _y1, int _x2, int _y2) {
		x1 = _x1; y1 = _y1; x2 = _x2; y2 = _y2;
	}
	P() {}

}p[MAXN];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#endif
	scanf("%d%d%d", &d, &n, &m);
	memset(T, 0, sizeof(T));
	memset(B, 0, sizeof(B));
	memset(L, 0, sizeof(L));
	memset(R, 0, sizeof(R));
	int x1, y1, x2, y2;
	for (int i = 0; i<d; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		p[i] = P(x1, y1, x2, y2);
		int ml = min(x1, x2), mr = max(x1, x2);
		int mt = min(y1, y2), mb = max(y1, y2);
		//	printf("%d %d %d %d\n", ml, mr, mt, mb);
		L[ml + 1]++; R[mr - 1]++;  T[mt + 1]++; B[mb - 1]++;
	}
	for (int i = 2; i <= n; i++)
		L[i] += L[i - 1], T[i] += T[i - 1];
	for (int i = n-1; i >= 1; i--)
		R[i] += R[i + 1], B[i] += B[i + 1];
	scanf("%d%d%d%d", &cntl, &cntr, &cntt, &cntb);

	int sum = 0;
	for (int i = 0; i<d; i++) {
		int ml = min(p[i].x1, p[i].x2), mr = max(p[i].x1, p[i].x2);
		int mt = min(p[i].y1, p[i].y2), mb = max(p[i].y1, p[i].y2);

		int numl = L[mr], numr = R[ml], numt = T[mb], numb = B[mt];
		if (p[i].x1 != p[i].x2) numl--, numr--;
		else numt--, numb--;

		//	printf("\n%d %d %d %d\n", ml, mr, mt, mb);
		//	printf("%d %d %d %d\n\n", numl, numr, numt, numb);

		if (numl == cntl&&numr == cntr&&numt == cntt
			&&numb == cntb) sum = i + 1;

	}
	if (sum == 0) printf("-1");
	else printf("%d", sum);
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <climits>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <sstream>
#define INF 0x3f3f3f3f
#define LL long long
#define fora(i,a,n) for(int i=a;i<=n;i++)
#define fors(i,n,a) for(int i=n;i>=a;i--)
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define MAXN 100024
const double eps = 1e-8;
using namespace std;
int d, n, m;
int T[MAXN], L[MAXN], R[MAXN], B[MAXN];
int cntl = 0, cntr = 0, cntt = 0, cntb = 0;
struct P {
	int x1, x2, y1, y2;
	P(int _x1, int _y1, int _x2, int _y2) {
		x1 = _x1; y1 = _y1; x2 = _x2; y2 = _y2;
	}
	P() {}

}p[10];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
	//freopen("out.txt","w",stdout);
#endif
	scanf("%d%d%d", &d, &n, &m);
	memset(T, 0, sizeof(T));
	memset(B, 0, sizeof(B));
	memset(L, 0, sizeof(L));
	memset(R, 0, sizeof(R));
	int x1, y1, x2, y2;
	for (int i = 0; i<d; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		p[i] = P(x1, y1, x2, y2);
		int ml = min(x1, x2), mr = max(x1, x2);
		int mt = min(y1, y2), mb = max(y1, y2);
		//	printf("%d %d %d %d\n", ml, mr, mt, mb);
		L[ml + 1]++; R[mr - 1]++;  T[mt + 1]++; B[mb - 1]++;
	}
	for (int i = 2; i <= n; i++)
		L[i] += L[i - 1], T[i] += T[i - 1];
	for (int i = n-1; i >= 1; i--)
		R[i] += R[i + 1], B[i] += B[i + 1];
	scanf("%d%d%d%d", &cntl, &cntr, &cntt, &cntb);

	int sum = 0;
	for (int i = 0; i<d; i++) {
		int ml = max(p[i].x1, p[i].x2), mr = min(p[i].x1, p[i].x2);
		int mt = max(p[i].y1, p[i].y2), mb = min(p[i].y1, p[i].y2);

		int numl = L[ml], numr = R[mr], numt = T[mt], numb = B[mb];
		if (p[i].x1 != p[i].x2) numl--, numr--;
		else numt--, numb--;

		//	printf("\n%d %d %d %d\n", ml, mr, mt, mb);
		//	printf("%d %d %d %d\n\n", numl, numr, numt, numb);

		if (numl == cntl&&numr == cntr&&numt == cntt
			&&numb == cntb) sum = i + 1;

	}
	if (sum == 0) printf("-1");
	else printf("%d", sum);
	return 0;
}


//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int d, n, m, vs[MAXN], cnt[4], has[MAXN][4];
vector<pii> dX, dY;

int main() {
#ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif

	cin >> d;
	cin >> n >> m;

	for (int i=0; i<d; i++) {
		int x, y;
		cin >> x >> y;
		dX.pb(mp(x, i));
		dY.pb(mp(y, i));
		cin >> x >> y;
		dX.pb(mp(x, i));
		dY.pb(mp(y, i));
	}

	for (int i=0; i<4; i++) cin >> cnt[i];

	sort(dX.begin(), dX.end());
	sort(dY.begin(), dY.end());

	int pass = 0;
	ms(vs, 0);
	for (int i=0; i<sz(dX); i++) {
		has[dX[i].SE][0] = max(has[dX[i].SE][0], pass);
		if (!vs[dX[i].SE]) {
			pass++;
			vs[dX[i].SE] = 1;
		}
	}

	pass = 0;
	ms(vs, 0);
	for (int i=sz(dX)-1; i>=0; i--) {
		has[dX[i].SE][1] = max(has[dX[i].SE][1], pass);
		if (!vs[dX[i].SE]) {
			pass++;
			vs[dX[i].SE] = 1;
		}
	}

	pass = 0;
	ms(vs, 0);
	for (int i=0; i<sz(dY); i++) {
		has[dY[i].SE][2] = max(has[dY[i].SE][2], pass);
		if (!vs[dY[i].SE]) {
			pass++;
			vs[dY[i].SE] = 1;
		}
	}

	pass = 0;
	ms(vs, 0);
	for (int i=sz(dY)-1; i>=0; i--) {
		has[dY[i].SE][3] = max(has[dY[i].SE][3], pass);
		if (!vs[dY[i].SE]) {
			pass++;
			vs[dY[i].SE] = 1;
		}
	}

	for (int i=0; i<d; i++) {
//		for (int j=0; j<4; j++) cout << has[i][j] << " ";
//		cout << endl;
		int check = 1;
		for (int j=0; j<4; j++) if (has[i][j] - 1 != cnt[j]) {
			check = 0;
			break;
		}
		if (check) {
			cout << i + 1;
			return 0;
		}
	}

	cout << -1;
	return 0;
}


//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int d, n, m, vs[MAXN], cnt[4], has[MAXN][4];
vector<pii> dX, dY;

int main() {
#ifndef ONLINE_JUDGE
    freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif

	cin >> d;
	cin >> n >> m;

	for (int i=0; i<d; i++) {
		int x, y;
		cin >> x >> y;
		dX.pb(mp(x, i));
		dY.pb(mp(y, i));
		cin >> x >> y;
		dX.pb(mp(x, i));
		dY.pb(mp(y, i));
	}

	for (int i=0; i<4; i++) cin >> cnt[i];

	sort(dX.begin(), dX.end());
	sort(dY.begin(), dY.end());

	int pass = 0;
	ms(vs, 0);
	int tot = 0;
	for (int i=0; i<sz(dX); i++) {
		if (i && dX[i].FI != dX[i - 1].FI) {
			tot += pass;
			pass = 0;
		}
		if (!vs[dX[i].SE]) {
			pass++;
			vs[dX[i].SE] = 1;
			has[dX[i].SE][0] = max(has[dX[i].SE][0], tot);
		}
		else {
			has[dX[i].SE][0] = max(has[dX[i].SE][0], tot - 1);
		}
	}

	pass = 0;
	ms(vs, 0);
	tot = 0;
	for (int i=sz(dX)-1; i>=0; i--) {
		if (i != sz(dX) - 1 && dX[i].FI != dX[i + 1].FI) {
			tot += pass;
			pass = 0;
		}
		if (!vs[dX[i].SE]) {
			pass++;
			vs[dX[i].SE] = 1;
			has[dX[i].SE][1] = max(has[dX[i].SE][1], tot);
		}
		else {
			has[dX[i].SE][1] = max(has[dX[i].SE][1], tot - 1);
		}
	}

	pass = 0;
	ms(vs, 0);
	tot = 0;
	for (int i=0; i<sz(dY); i++) {
		if (i && dY[i].FI != dY[i - 1].FI) {
			tot += pass;
			pass = 0;
		}
		if (!vs[dY[i].SE]) {
			pass++;
			vs[dY[i].SE] = 1;
			has[dY[i].SE][2] = max(has[dY[i].SE][2], tot);
		}
		else {
			has[dY[i].SE][2] = max(has[dY[i].SE][2], tot - 1);
		}
	}

	pass = 0;
	ms(vs, 0);
	tot = 0;
	for (int i=sz(dY)-1; i>=0; i--) {
		if (i != sz(dY) - 1 && dY[i].FI != dY[i + 1].FI) {
			tot += pass;
			pass = 0;
		}
		if (!vs[dY[i].SE]) {
			pass++;
			vs[dY[i].SE] = 1;
			has[dY[i].SE][3] = max(has[dY[i].SE][3], tot);
		}
		else {
			has[dY[i].SE][3] = max(has[dY[i].SE][3], tot - 1);
		}
	}

	for (int i=0; i<d; i++) {
//		for (int j=0; j<4; j++) cout << has[i][j] << " ";
//		cout << endl;
		int check = 1;
		for (int j=0; j<4; j++) if (has[i][j] != cnt[j]) {
			check = 0;
			break;
		}
		if (check) {
			cout << i + 1;
			return 0;
		}
	}

	cout << -1;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
 int d;
 int n, m;
 cin >> d >> n >> m;
 vector<int> x1(d);
 vector<int> y1(d);
 vector<int> x2(d);
 vector<int> y2(d);
 vector<int> xx(d);
 vector<int> yy(d);
 for (int i = 0; i < d; ++i) {
   cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
   xx[i] = x1[i] + x2[i];
   yy[i] = y1[i] + y2[i];
 }
 sort(xx.begin(), xx.end());
 sort(yy.begin(), yy.end());
 int l, r, t, b;
 cin >> l >> r >> t >> b;
 int vl = xx[l];
 int vr = xx[d - r - 1];
 int vt = yy[t];
 int vb = yy[d - b - 1];
 int idx = -1;
 if (vl == vr && vb == vt) {
   if ((l == d - 1 || xx[l + 1] != vl)
       && (r == d - 1 || xx[d - r - 1 - 1] != vr)
       && (t == d - 1 || yy[t + 1] != vt)
       && (b == d - 1 || yy[d - b - 1 - 1] != vb)) {
     for (int i = 0; i < d; ++i) {
       if (x1[i] + x2[i] == vl && y1[i] + y2[i] == vt) {
          idx = i + 1;
          break;
       }
     }
   }
 }
 cout << idx << endl;
 return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <memory>
#include <cstring>
using namespace std;

#include <stdio.h>
#include <stdlib.h>

int main() {
  map<int, int> h;
  map<int, int> v;
  int d, n, m;
  cin >> d >> n >> m;
  vector<int> x1(d);
  vector<int> x2(d);
  vector<int> y1(d);
  vector<int> y2(d);
  for (int i = 0; i < d; ++i) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    h[x1[i] + x2[i]]++;
    v[y1[i] + y2[i]]++;
  }
  int l, r, t, b;
  cin >> l >> r >> t >> b;
  int ll = l;
  int hsum;
  for (auto ii = h.begin(); ii != h.end(); ++ii) {
    int cur = ii->second;
    if (ll < cur - 1) {
        cout << - 1 << endl;
        return 0;
    } else if (ll > cur - 1) {
        ll -= cur;
    } else {
        if (l + r != d - cur + cur - 1 + cur - 1) {
            cout << -1 << endl;
            return 0;
        }
        hsum = ii->first;
        break;
    }
  }
  int tt = t;
  int vsum;
  for (auto ii = v.begin(); ii != v.end(); ++ii) {
    int cur = ii->second;
    if (tt < cur - 1) {
        cout << - 1 << endl;
        return 0;
    } else if (tt > cur - 1) {
        tt -= cur;
    } else {
        if (t + b != d - cur + cur - 1 + cur - 1) {
            cout << -1 << endl;
            return 0;
        }
        vsum = ii->first;
        break;
    }
  }
  for (int i = 0; i < d; ++i) {
    if (x1[i] + x2[i] == hsum && y1[i] + y2[i] == vsum) {
        cout << i + 1 << endl;
        return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <memory>
#include <cstring>
using namespace std;

#include <stdio.h>
#include <stdlib.h>

int main() {
  map<int, int> h;
  map<int, int> v;
  int d, n, m;
  cin >> d >> n >> m;
  vector<int> x1(d);
  vector<int> x2(d);
  vector<int> y1(d);
  vector<int> y2(d);
  for (int i = 0; i < d; ++i) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    h[x1[i] + x2[i]]++;
    v[y1[i] + y2[i]]++;
  }
  int l, r, t, b;
  cin >> l >> r >> t >> b;
  int ll = l + 1;
  int hsum;
  for (auto ii = h.begin(); ii != h.end(); ++ii) {
    int cur = ii->second;
    if (ll > cur) {
        ll -= cur;
    } else {
        if (l + r > d - cur + cur - 1 + cur - 1) {
            cout << -1 << endl;
            return 0;
        }
        hsum = ii->first;
        break;
    }
  }
  int tt = t + 1;
  int vsum;
  for (auto ii = v.begin(); ii != v.end(); ++ii) {
    int cur = ii->second;
    if (tt > cur) {
        tt -= cur;
    } else {
        if (t + b > d - cur + cur - 1 + cur - 1) {
            cout << -1 << endl;
            return 0;
        }
        vsum = ii->first;
        break;
    }
  }
  for (int i = 0; i < d; ++i) {
    if (x1[i] + x2[i] == hsum && y1[i] + y2[i] == vsum) {
        cout << i + 1 << endl;
        return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
 int d;
 int n, m;
 cin >> d >> n >> m;
 vector<int> x1(d);
 vector<int> y1(d);
 vector<int> x2(d);
 vector<int> y2(d);
 vector<int> xx(d);
 vector<int> yy(d);
 for (int i = 0; i < d; ++i) {
   cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
   xx[i] = x1[i] + x2[i];
   yy[i] = y1[i] + y2[i];
 }
 sort(xx.begin(), xx.end());
 sort(yy.begin(), yy.end());
 int l, r, t, b;
 cin >> l >> r >> t >> b;
 int vl = xx[l];
 int vr = xx[d - r - 1];
 int vb = yy[t];
 int vt = yy[d - b - 1];
 if (vl != vr || vb != vt) {
   cout << -1 << endl;
 } else {
   int idx = -1;
   for (int i = 0; i < d; ++i) {
     if (x1[i] + x2[i] == vl && y1[i] + y2[i] == vt) {
        idx = i + 1;
        break;
     }
   }
   cout << idx << endl;
 }
 return 0;
}