def run():
  N, M = map(int, input().split())
  sc = [tuple(map(int, input().split())) for m in range(M)]
  ans = [10]*N
  for s, c in sc:
    if ans[s-1] == 10:
      ans[s-1] = c
    else:
      if ans[s-1] == c:
        continue
      else:
        print(-1)
        exit()
  if ans == [0]:
    print(0)
    exit()
  if ans[0] == 0:
    print(-1)
  else:
    for n in range(N):
      if ans[n] == 10:
        ans[n] = 0
    print(''.join(map(str, ans)))
    
if __name__ == '__main__':
  run()