n,m = list(map(int, input().split()))
x = []
ans = [0]*n
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)
  
if m == 0:
  print(-1)
#sに重複があれば－１を出力
elif has_duplicates(s):
  print(-1)
elif (n == 1) and (c.count(0) == 1):
  print(0)
else:
  for i,j in x:
    ans[i-1] = j
    
  if (ans[0] == 0) and (s.count(1) == 0):
    ans[0] = 1
    
  for i in range(len(ans)):
    answ += ans[i]*(10**(n-1-i))

  if ans[0] == 0:
    print(-1)
  else:
    print(answ)