N, M = map(int, input().split())
check = [set() for i in range(N)]
ans = 0

for i in range(M):
  S, C = map(int, input().split())
  check[S-1].add(C)
  
for i in range(N):
  if len(check[i]) > 1:
    ans = -1
    break
  elif len(check[i]) == 1:
    num = check[i].pop()
    if i == 0 and num == 0:
      ans = -1
      break
    ans += num * (10 ** (N-i-1))
    
print(ans)