import sys
n, m = map(int, input().split())

num=[0]*n
num[0]=1
bl=[False]*n
for i in range(m):
    s,c=map(int,input().split())
    if s==1:
        if c==0:
            if n!=1:
                print(-1)
                sys.exit()
            else:
                print(0)
                sys.exit()
        elif bl[0] is True and c!=num[0]:
            print(-1)
            sys.exit()
        else:
            num[0]=c
            bl[0]=True
    else:
        if bl[s-1] is True and c!=num[s-1]:
            print(-1)
            sys.exit()
        else:
            num[s-1]=c
            bl[s-1]=True


    
ans=""
for i in num:
    ans=ans+str(i)

print(ans)