n,m=map(int,input().split())
num=[0 for i in range(n)]
ans=0
for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
        ans=1
        break
    if num[s-1]==0 or num[s-1]==c:
        num[s-1]=c
    else:
        ans=1
        break

if ans==0:
    if num[0]==0:
        num[0]=1
    for i in num:
        print(i,end="")
else:
    print(-1)