import sys
n,m=map(int,input().split())
data=[0]*n
for i in range(m):
    s,c=map(int,input().split())
    if data[s-1]!=0 and data[s-1]!=c:
        print(-1)
        sys.exit()
    if s==1 and c==0:
        print(-1)
        sys.exit()
    data[s-1]=c
if data[0]==0:
    data[0]=1
ans=0
for i in range(n):
    ans+=data[i]*10**(n-i-1)
print(ans)