n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for l in range(m)]
b=[int(-1) for _ in range(n)]
for x in a:
    if b[x[0]-1]==-1:b[x[0]-1]=x[1]
    elif x[1]!=b[x[0]-1]:
        print(-1)
        exit(0)
if b[0]==0:
    print(-1)
    exit(0)
if b[0]==-1:b[0]=1
for i in range(1,n):
    if b[i]==-1:b[i]=0
print("".join(map(str,b)))