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