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