#157c
N,M = map(int, input().split())

ans = ["?" for i in range(N)]

for i in range(M):
    s,c = map(int, input().split())
    
    if ans[s-1] != "?" and ans[s-1] != str(c): 
        print(-1)
        break
    else:
        ans[s-1] = str(c)
else:
    if ans[0] == "0":
        print(-1)
    else:
        for i in range(N):
            if ans[i] == "?":
                ans[i] = "0"
        print(str(''.join(ans)))