N, M = map(int, input().split())
SC = [list(map(int, input().split())) for i in range(M)]
Ans = ['0', '0', '0']
judge = 0

if M == 0:
#Mの束縛がないとき
  if N == 1:
    print(0)
  
  elif N == 2:
    print(10)
  
  else:
    print(100)

else:
#Mの束縛があるとき
#
  for j in range(M):
    if Ans[SC[j][0]-1] == '0' or Ans[SC[j][0]-1] == str(SC[j][1]):
      Ans[SC[j][0]-1] = str(SC[j][1])
    
    else:
      judge = 1

if judge == 0:
  L = ''.join(Ans)
  print(int(L))

else:
  print(-1)
      
