N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]
if(M > N):
  print(-1)
else:
  ans = [0] * N
  used = []
  for i in range(M):
    if(ans[SC[i][0] - 1] != SC[i][1] and SC[i][0] in used):
      print(-1)
      break
    elif(SC[i][0] == 1 and SC[i][1] == 0):
      print(-1)
      break
    else:
      ans[SC[i][0] - 1] = SC[i][1]
      used.append(SC[i][0])
  else:
    if(ans[0] == 0):
      ans[0] = 1
    print(''.join([str(n) for n in ans]))