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