N, M = map(int, input().split())
X = [list(map(int, input().split())) for i in range(M)]
ans =[]
X.sort(reverse = True)

for i in range(N):
  if i == 0:
    ans.append(1)
  
  else:
    ans.append(0)

for j in range(M):
  if X[j][0] == 1:
    if ans[X[j][0]-1] == X[j][1] or ans[X[j][0]-1] == 1:
      ans[X[j][0]-1] = X[j][1]
      
    else:
      ans = '-1'
      break
      
  else:
    if ans[X[j][0]-1] == X[j][1] or ans[X[j][0]-1] == 0:
      ans[X[j][0]-1] = X[j][1]
      
    else:
      ans = '-1'
      break
    
if N >= 2 and ans[0] == 0:
  print(-1)
  
else:
  ansstr = list(map(str, ans))
  ans = ''.join(ansstr)
  print(int(ans))