n,m = map(int, input().split())
ans_n = [0]*n
check = [0]*n
for _ in range(m):
    s,c = map(int, input().split())
    if n==1:
        if check[s-1]==1 and ans_n[s-1]!=c:
            print(-1)
            exit()
        else:
            ans_n[s-1]=c
            check[s-1] = 1
    else:
        if s==1 and c==0:
            print(-1)
        elif check[s-1]==1 and ans_n[s-1]!=c:
            print(-1)
            exit()
        else:
            ans_n[s-1]=c
            check[s-1] = 1

ans = 0
for i in range(n):
    if check[0]==1:
        if check[i]==1:
            ans += ans_n[i]*(10**(n-1-i))
    else:
        if check[i]==1:
            ans += ans_n[i]*(10**(n-1-i))
print(ans)
