n,m=map(int,input().split())
# a,b,c=map(int,input().split())
# s=input()
# s,t=map(str,input().split())

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

if m==0:
  if n==1:
    print(0)
  else:
    print(-1)
  exit()

if ans[0]==-1:
  ans[0]="1"



for x in ans:
  if x==-1:
    x=0
  anss+=str(x)
print(anss)
