N,M = map(int,input().split())
a = list("0"*N)
used = []
count = 0
for i in range(M):
    s,c = map(int,input().split())
    if used.count([s,c])==0:
        used.append([s,c])
    else:
        count += 1
    if int(a[s-1])>=c or int(a[s-1])==0:
        a[s-1] = str(c)
ans = "".join(a)

K = len(set(sum(used,[])))//2 + count
if K==N and a[0]!=0 or int(ans)==0 and K==N:
    print(int(ans))
else:
    print(-1)