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

## make direcctory ## init_val = 0
out = {}
num = ""
flag = 0
num_flag = {}
for i in range(1,N+1):
  out[i] = 0
  num_flag[i] = 0
## 値の変更 ##
for i in range(1,M+1):
  digit,val = map(int,input().split())
  ## 値が初期値、かつ、値指定されていない時 ##
  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 ##
if flag == 1:
  print("-1")
elif out[1] == 0:
  print("-1")
else:
  for i in out:
    num = num+str(out[i])
  print(num)