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

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):
        mm = li[i]
        if li[i]==-1 and i!=0:
            li[i] = 0
        elif li[i]==-1 and i==0:
            li[i] = 1
        ans = ans * 10 + li[i]
    if ans > 0:
        print(ans)
    else:
        print(-1)
    

