n = input().rstrip().split(' ')
N = int(n[0])
M = int(n[1])

s = []
c = []

for i in range(M):
  S = input().rstrip().split(' ')
  s.append(int(S[0]))
  c.append(int(S[1]))

a = []
n = 0
flag = 0
for i in range(M):
  for j in range(i + 1, M):
    if s[i] == s[j] and c[i] != c[j]:
      print("-1")
      flag = 1
      break
    else:
      a.append([s[i], c[i]])
      if s[i] > n:
        n = s[i]
  if flag == 1:
    break
if flag == 0:
  i = 0
  while i > 0:
    print(c[i],end="")
    i -= 1