N, M=map(int, input().split())
lst=[None]*M
for i in range(M):
    lst[i]=tuple(map(int, input().split()))

#print(N, M, lst)
digit=[]
for _ in range(N):
    digit.append([])

for val in lst:
    digit[val[0]-1].append(val[1])
#print(digit)

num=0

if N==3 and 0 in digit[0]:
    print(-1)
elif N==2 and 0 in digit[0]:
    print(-1)
else:
    for i in range(N):
        if len(set(digit[i]))>=2:
            print(-1)
            break
        elif digit[i]:
            num+=digit[i][0]*10**(N-i-1)
    else:
        print(num)

