n,m = list(map(int, input().split()))
x = []
ans = [0]*m
answ = 0
s,c = [], []

def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(m):
  x.append(list(map(int,input().split())))
  
#重複を取り除く
x = list(map(list, set(map(tuple, x))))

for i,j in x:
  s.append(i)
  c.append(j)
  
#sに重複があれば－１を出力
if has_duplicates(s):
  print(-1)
else:
  for i,j in x:
    ans[i-1] = j
    
  if ans.count(0) == m:
    print(-1)
  else:
    for i in range(len(ans)):
      answ += ans[i]*(10**(m-1-i))
    
    if len(str(answ)) == n:
    	print(answ)
    else:
      print(-1)