N,M = map(int, input().split())
ans=0
if M!=0:
  s=[0]*M
  c=[0]*M
  for i in range(M):
    s[i],c[i]=map(int, input().split())
    s[i]-=1
else:
  ans=10**(N-1)
flag=[0]*N
value=[0]*N
for i in range(N):
  flag[i]=0
  value[i]=0
if (M!=0):
  for i in range(M):
    if flag[s[i]]==0:
      flag[s[i]]=1
      value[s[i]]=c[i]
      ans+=c[i]*(10**(N-1-s[i]))
    elif c[i]==value[s[i]]:
      continue
    else:
      ans=-1
      break
  if ans!=-1:
    if (flag[0]==1 and value[0]==0):
      ans=-1
  if ans!=-1 and ans<10**(N-1):
    ans+=10**(N-1)
elif (M!=0):
  ans=-1
  
print(ans)