N,M=map(int,input().split())
l=[]
for i in range(N):
    l.append([i,0])

f=True
for _ in range(1,M+1):
    a,b=map(int,input().split())
    if l[a-1][1]==0 or l[a-1][1]==b:
        l[a-1][1]=b
    else:
        f=False
if f==False or (N>1 and l[0][1]==0):
    print(-1)
else:
    for i in range(N):
        print(str(l[i][1]),end="")

