import sys
N,M = map(int,input().split())
s = [0]*M
c = [0]*M
ans = [0]*N
for i in range(M):
    s[i],c[i] = map(int,input().split())
if N != 1:
    if M == 0:
        print(10,N)
        sys.exit()
    else:
        for i in range(M):
            if s[i] == 1 and c[i] == 0:
                print(-1)
                sys.exit()
if M !=0:
    for i in range(M):
        for j in range(i+1,M):
            if s[i] == s[j] and c[i] != c[j]:
                print(-1)
                sys.exit()
    for i in range(M):
        ans[s[i]-1] = c[i]
    for i in range(N):
        print(ans[i], end="")
if N == 1 and M == 0:
    print(0)
