N,M = map(int,input().split())
sc = []
for _ in range(M):
  s,c = map(int,input().split())
  for i in range(len(sc)):
    if s == sc[i][0]:
      if c != sc[i][1]:
        print(-1)
        exit()
  sc.append([s,c])
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
sc = get_unique_list(sc)
ans = 0
for a in range(1,N+1):
  for row in sc:
    if a == row[0]:
      ans += row[1]*(10**(N-a))

if len(str(ans)) == N:
  print(ans)
else:
  print(-1)