import sys
n,m=map(int,input().split())
tmp=[]
ans=[0]*n
for _ in range(m):
    tmp.append(list(map(int,input().split())))
for i in tmp:
    if i[0]==1 and i[1]==0:
        print(-1)
        sys.exit()
    else:
        if ans[i[0]-1]!=0 and i[1]!=ans[i[0]-1]:
            print(-1)
            sys.exit()
        ans[i[0]-1]=i[1]
if n==1:
    print(ans[0])
elif n==2:
    print(10*ans[0]+ans[1])
else:
    print(100*ans[0]+10*ans[1]+ans[2])