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