## 1<=N<=3 0<=M<=5
N,M = map(int,input().split())

## make direcctory ## init_val = 0
out = {}		#各桁の値
num_flag = {}	#各桁を書換えた回数
for i in range(1,N+1):
  out[i] = 0
  num_flag[i] = 0

## 値の変更 ##
flag = 0
for i in range(1,M+1):
  digit,val = map(int,input().split())
  ## 値0、かつ、その桁に対して値未指定の時 ##
  if out[digit] == 0 and num_flag[digit] == 0: 
    out[digit] = val
    num_flag[digit] = num_flag[digit] + 1
  ## 値が更新済みの時 ##
  elif out[digit] == val:
    out[digit] = val
  else:
    flag = 1
    break

## O/P ##
num = ""
if flag == 1:
  print("-1")
elif out[1] == 0:
  out[1] == 1
  num = "1"
  for i in range(2,N+1):
    num = num+str(out[i])
  print(num)  
else:
  for i in out:
    num = num+str(out[i])
  print(num)