keta,num=map(int,input().split())
list=[list(map(int,input().split())) for i in range(num)]

ans = [0]*keta
for i in range(num):
  if ans[list[i][0]-1] < list[i][1]:
    ans[list[i][0]-1] = list[i][1]
  
if ans[0] == 0:
  print(-1)
else:
  print(str(ans[0])+str(ans[1]) + str(ans[2]))
  


