import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

n, m = map(int, readline().split())
tf = [False] * (n + 1)
s = ['0'] * n
for _ in range(m):
  a, b = readline().split()
  a = int(a)
  if not tf[a]:
    s[a-1]=b
    tf[a] = True
  else:
    if s[a-1]==b:
      continue
    else:
      print(-1)
      quit()
if s[0] == '0':
  print(-1)
else:
  print(''.join(s))