ans = 0
N, M = map(int, input().split())

l = ['']*N
for _ in range(M):
  s, c = input().split()
  if l[int(s)-1] == '' or l[int(s)-1] == c:
    l[int(s)-1] = c
  else:
    ans = -1
    break
else:
  for i in range(N):
    if l[i] == '':
      l[i] = '0'
  ans = ''.join(l)
  if ans[0] == '0' and len(ans) > 1:
    ans = -1
print(ans)