import numpy as np
N,M=map(int, input().split())  
sc=np.array([list(map(int,list(input().split()))) for i in range(M)])

ans = np.zeros(N)
checked=False
for i in range(M):
  s=sc[i][0]
  c=sc[i][1]
  if s==1 and c==0:
    checked=True
    break
  for j in range(i):
    if s==sc[j][0] and c!=sc[j][1]:
      checked=True
      break
  ans[s-1] = c

if checked:
  print(-1)
else:
  res = ''
  for i in ans:
    res += str(int(i))
  print(int(res))