n, m = map(int, input().strip().split())
a = [input().split() for i in range(m)]
ans = ['a'] * n


for i in range(m):
  ind = int(a[i][0]) - 1
  if ans[ind] != 'a':
    ans = '-1'
    break
  else:
    ans[ind] = a[i][1]

print(''.join(ans))