n,m=map(int,input().split())
list=[list(map(int,input().split())) for _ in range(m)]
flag=False
ans=['0']*n
for i in range(m):
  if list[i][0]==n:
    flag=True
  for j in range(i+1,m):
    if list[i][0]==list[j][0] and list[i][1]!=list[j][1]:
      print('-1')
      exit()
  ans[list[i][0]-1]=str(list[i][1])
if flag==True:
  print(''.join(ans))
else:
  print('-1')