import sys
N,M = map(int,input().split())
s = [0] * M
c = [0] * M
a = ["1"] + ["0"] * (N-1)
for i in range(M):
    s[i],c[i] = map(int,input().split())
for j in range(N):
    if s[j] == 1 and c[j] == 0:
        print(-1)
        sys.exit()
    elif a[s[j]-1] == "0" or (s[j] == 1 and a[0] == "1"):
        a[s[j]-1] = str(c[j])
    elif a[s[j]-1] == str(c[j]):
        pass
    else:
        print(-1)
        sys.exit()
ans = "".join(a)
print(int(ans))