N,M=map(int,input().split())
l=[0]*N
ans=0
for i in range(M):
    s,c=map(int,input().split())
    if l[s-1]==0 or l[s-1]==c:
        l[s-1]=c
    else:
        print(-1)
        exit()
    if s==1 and c==0:
        print(-1)
        exit()
for i in range(N):
    ans+=int(l[i])*(10**(N-i-1))
if N==len(str(ans)):
    print(ans)
else:
    print(10**(N-1)+ans)



        



