n,m=map(int,input().split())
ans=[0]*n
 
for i in range(m):
    a,b=map(int,input().split())
    
    if ans[a-1]==0 or ans[a-1]==b:
        ans[a-1]=b
    else:
        print(-1)
        exit()


if n>1 and ans[0]==0:
    print(-1)
elif n==1:
    print(ans)
else:
    for j in range(n-1):
        print(ans[j], end="")
    print(ans[-1])