N,M=map(int,input().split())
ans=[-1]*N
flag=True
sc = [map(int, input().split()) for _ in range(M)]
s, c = [list(i) for i in zip(*sc)]
x=0
for i in range(M):
  s1=s[i]
  c1=c[i]
  if(ans[s1-1]==-1):
    ans[s1-1]=c1
  elif(ans[s1-1]!=c1):
    flag=False
  if(N>1 and c1==0):
    flag=False
if(flag==False):
  print("-1")
else:
  for i in range(N):
    if(N==1):
      if(ans[i]==-1):
        ans[i]=0
    else:
      if(i==0 and ans[i]==-1):
        ans[i]=1
      elif(ans[i]==-1):
        ans[i]=0
  for j in range(N):
    x+=ans[j]*(10**(N-j-1))
  print(x)