N,M = map(int,input().split())
n = [0]*N
n_used = [False]*N
if N > 1:
    n[0]=1
for i in range(0,M,1):
    s,c = map(int,input().split())
    if (n_used[s-1] and n[s-1]!=c) or (s==1 and c ==0 and N != 1):
        print(-1)
        exit()
    else:
        n[s-1]=c
        n_used[s-1]=True

print("{}{}{}".format(n[0],n[1],n[2]))