N,M = map(int,input().split())
li = [-1 for i in range(N)]

for i in range(M):
    s,c = map(int,input().split())
    if c == 0 and s==1:
        print("-1")
        break

    if li[s-1]==-1 or li[s-1]==c:
        li[s-1] = c
    else:
        print("-1")
        break
else:
    ans = 0
    for i in range(N):
        if li[i]==-1:
            li[i] = 0
        ans = ans * 10 + li[i]
    print(ans)
    

