line_b = list(map(int, input().split(' ')))
line=[]
num=[]
for i in range(line_b[1]):
  line+=[list(map(int, input().split(' ')))]
  num+=[0]
for i in range(line_b[1]):
  if num[line[i][0]-1]==0:
    num[line[i][0]-1]=line[i][1]
  elif num[line[i][0]-1]!=line[i][1]:
    num[0]=0
    break
if num[0]==0:
  print(-1)
else:
  print("%d%d%d" %(num[0],num[1],num[2]))