N,M = list(map(int,input().split()))
SC = [0]*(N+1)
if M == 0:
  print(1*10**(N-1))
  exit()
for m in range(M):
  sc = list(map(int,input().split()))
  if (sc[0] == 1) and (sc[1] == 0):
    print(-1)
    exit()
  elif sc[0] > N:
    print(-1)
    exit()
  elif SC[sc[0]] == 0:
    SC[sc[0]] = sc[1]
  else:
    if SC[sc[0]] != sc[1]:
      print(-1)
      exit()


if SC[1]==0:
  SC[1] = 1
ans = 0
for i in range(N):
  ans += 10**(N-i-1)*SC[i+1]

print(ans)
