n, m = map(int, input().split())
s = [0] * m
c = [0] * m
for i in range(m):
  s[i], c[i] = map(int, input().split())
  
ans = 0
N = [[] for i in range(n)]
for i in range(n):
  N[i] = [c[j] for j, x in enumerate(s) if x == i+1]
  if len(N[i]) > 1:
    N[i] = list(set(N[i]))
  
  if len(N[i]) > 1:
    ans = -1
    break
  elif len(N[i]) == 0:
    continue
  else:
    ans += N[i][0] * (10 ** (n-1-i) )
    
if ans != -1 and n != 1 and N[0][0] == 0:
  ans = -1

print(ans)