#READING AND ORDERING
fin=open("cowjump.in", "r")
lines=fin.readlines()
n=int(lines[0])
lines.remove(lines[0])

#Sweep
points=[]
for i in range(n):
    lines[i]=lines[i].split()
    lines[i]=[int(x) for x in lines[i]]
    beg=lines[i][0]>lines[i][2]
    
    points.append([lines[i][0], lines[i][1], beg, i])
    points.append([lines[i][2], lines[i][3], not beg, i])

def my_key_function(entry):
    return(entry[0], entry[2])
points=sorted(points, key=my_key_function)

def box_inter(a, b):
    return min(a[0], a[2])<=max(b[0], b[2]) and max(a[0], a[2])>=min(b[0], b[2]) and min(a[1], a[3])<=max(b[1], b[3]) and max(a[1], a[3])>=min(b[1], b[3])


active=[]
count=0
inters=[]
final=0
i=-1

for i in range(len(points)):
    if final!=0:
        break
    if not points[i][2]: #Left point
        #active=sorted(active, key=lambda entry: entry[1])
        found=False
        for j in range(len(active)):
            x1=lines[points[i][3]][0]
            y1=lines[points[i][3]][1]
            x2=lines[points[i][3]][2]
            y2=lines[points[i][3]][3]
            x3=active[j][0]
            y3=active[j][1]
            x4=active[j][2]
            y4=active[j][3]

            if x2!=x1:
                m1=(y2-y1)/(x2-x1)
            else:
                m1=n
            if x4!=x3:
                m2=(y4-y3)/(x4-x3)
            else:
                m2=n
            if m2!=m1:
                x=(m1*x1-y1-m2*x3+y3)/(m1-m2)
                if (x1<x<x2 or x2<x<x1) and (x3<x<x4 or x4<x<x3):
                    index1=i
                    index2=j
                    j=len(active)-1
                    if index1+1 in inters:
                        final=points[index1][3]+1
                    elif index2+1 in inters:
                        final=points[index2][3]+1
                    else:
                        inters.append(index1+1)
                        inters.append(index2+1)
                        found=True
        active.append(lines[points[i][3]])
        
    else: #Right point
        active.remove(lines[points[i][3]])





"""
def box_inter(a, b):
    return min(a[0], a[2])<=max(b[0], b[2]) and max(a[0], a[2])>=min(b[0], b[2]) and min(a[1], a[3])<=max(b[1], b[3]) and max(a[1], a[3])>=min(b[1], b[3])

found=False
index1=0
index2=0
for i in range(n-1):
    for j in range(i+1, n):
        if box_inter(lines[i], lines[j]):
            x1=lines[i][0]
            y1=lines[i][1]
            x2=lines[i][2]
            y2=lines[i][3]
            x3=lines[j][0]
            y3=lines[j][1]
            x4=lines[j][2]
            y4=lines[j][3]

            if x2!=x1:
                m1=(y2-y1)/(x2-x1)
            else:
                m1=n
            if x4!=x3:
                m2=(y4-y3)/(x4-x3)
            else:
                m2=n
            if m2!=m1:
                x=(m1*x1-y1-m2*x3+y3)/(m1-m2)
                if x1<x<x2 and x3<x<x4 and not found:
                    index1=i
                    index2=j
                    i=n-2
                    j=n-1
                    found=True

index1s=0
found=False
for j in range(n):
    if box_inter(lines[index1], lines[j]):
        x1=lines[index1][0]
        y1=lines[index1][1]
        x2=lines[index1][2]
        y2=lines[index1][3]
        x3=lines[j][0]
        y3=lines[j][1]
        x4=lines[j][2]
        y4=lines[j][3]

        if x2!=x1:
            m1=(y2-y1)/(x2-x1)
        else:
            m1=n
        if x4!=x3:
            m2=(y4-y3)/(x4-x3)
        else:
            m2=n
        if m2!=m1:
            x=(m1*x1-y1-m2*x3+y3)/(m1-m2)
            if x1<x<x2 and x3<x<x4 and not found:
                index1s+=1
                if index1s==2:
                    found=True
a=""
if found:
    a=str(index1+1)+"\n"
else:
    a=str(index2+1)+"\n"

"""
a=str(final)+"\n"
#print(a)
fout=open("cowjump.out", "w")
fout.write(a)
fout.close()
