N,M = map(int,input().split())

## make direcctory ## init_val = 0
out = {}
num = ""
flag = 0
for i in range(1,N+1):
  out[i] = 0

## 値の変更 ##
for i in range(1,M+1):
  digit,val = map(int,input().split())
  if out[digit] == 0:
    out[digit] = val
  elif out[digit] != val:
    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)