N, M = map(int, input().split())
sc = [list(map(int,input().split())) for i in range(M)]

sc = list(map(list, set(map(tuple, A))))
for i in range(len(sc)):
    tmp0 = sc[i][0]
    tmp1 = sc[i][1]
    for j in range(1, len(sc)-i+1):
        if tmp0 == sc[-j][0] and tmp1 != sc[-j][1]:
            print(-1)
            exit()

if N == 3:
    #for i in range(100,1000):
        #i_str = str(i)
    for j in range(len(sc)):
        if sc[j][0] == 1 and sc[j][0] == 0:
            print(-1)
            exit()
        if sc[j][0] == 1:
            num = sc[j][1]
print(-1)