import sys
n,m=map(int,input().split())
key=[-1 for i in range(n)]
ans=-1
f=False
for i in range(m):
    s,c=map(int,input().split())
    if key[s-1]==-1:
        key[s-1]=c
    elif key[s-1]!=c:
        print(-1)
        sys.exit()
for i in range(n):
    if key[i]==-1:
        if i!=0:
            key[i]=0
        elif n==1:
            key[i]=0
        else:
            key[i]=0
    key[i]=str(key[i])
ans=int("".join(key))
if 10**(n-1)<=ans<10**n:
  print(ans)
elif n==1 and ans==0:
  print(0)
else:
  print(-1)

