line_b = list(map(int, input().split(' ')))
line=[]
num=[]
for i in range(line_b[0]):
  num+=[0]
for i in range(line_b[1]):
  line+=[list(map(int, input().split(' ')))]
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]!=0 and num[line[i][0]-1]!=line[i][1]:
    num[0]=0
    i=line_b[1]
if num[0]==0 or num[0]<0 or num[1]<0 or num[2]<0:
  print(-1)
else:
  print("%d%d%d" %(num[0],num[1],num[2]))