N, M=map(int, input().split())
sc=[list(map(int, input().split())) for i in range(M)]

num=[-1]*N
for i in range(M):
  if num[sc[i][0]-1]!=-1:
    if num[sc[i][0]-1]!=sc[i][1]:
      print('-1')
      exit()
    else:
      pass
  else:
    num[sc[i][0]-1]=sc[i][1]
    
if num[0]==0:
  print('-1')
  exit()
  
if num[0]==-1:
  num[0]=1
for i in range(1, N):
  if num[i]==-1:
    num[i]=0
    
num=[str(num[i]) for i in range(N)]
print(''.join(num))