n,m = map(int, input().split())
sc= [map(int, input().split()) for _ in range(m)]
s, c = [list(i) for i in zip(*sc)]



for ans in range(10**n):
    ans = str(ans)
    if len(ans) == n and all(ans[s[j]-1] == str(c[j]) for j in range(m)):
        print(ans)
        exit()
print(-1)