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]!=line[i][1]:
    num[0]=0
    break
for i in range(line_b[1]):
  for j in range(line_b[1]):
    if line[i][0]==line[j][0] and line[i][1]!=line[j][1]:
      num[0]=0
if num[0]==0:
  print(-1)
else:
  number=0
  for i in range(line_b[0]):
    number+=num[i]*10**(line_b[0]-1-i)
  print("%d" %number)