N,m = map(int,input().split())
n = [-1]*N
for i in range(m):
    s,c = map(int,input().split())
    if n[s-1] == c or n[s-1] == -1:
        n[s-1] = c
    else:
        print(-1)
        exit()
ans = ""
for i in n:
    if i == -1:
        ans += "0"
    else:
        ans += str(i)
if ans[0] == "0":
    print(-1)
else:
    print(ans)