N,M = map(int,input().split())
s = []
c = []
for i in range(M):
    s1,c1=[int(i) for i in input().split()]
    s.append(s1)
    c.append(c1)

ans = [10 for i in range(N)]
x = ''
for j in range(M):
  if ans[s[j]-1] == 10:
     ans[s[j]-1] = c[j]
  elif ans[s[j]-1] != 10 and  ans[s[j]-1] != c[j]:
    print('-1')
    exit()
  
for k in range(N):
  if ans[k] == 10:
    ans[k] = 0
if ans[0] == 0 :
  print('-1')
else :
  for l in range(N):
    x += str(ans[l])
  print(x)
   
  
