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

num = ["0","0","0"]

for i in l:
    num[i[0]-1] = str(i[1])
    
ans = "".join(num)

for i in l:
    if i[0] == 1 and i[1] == 0:
        print(-1)
        exit()
    if ans[i[0]-1] != str(i[1]):
        print(-1)
        exit()
print(int(ans))