N, M = map(int, input().split())

sc = [list(map(int, input().split())) for i in range(M)]

ans = 0

for i in range(M-1):
  for j in range(i+1, M):
    if sc[i][0]==sc[j][0] and sc[i][1]!=sc[j][1]:
      ans = -1

for i in range(M):
  if N>1 and sc[i][0]==1 and sc[i][1]==0:
    ans = -1

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

if M == 0:
  ans = 10**(N-1)
  if N == 1:
    ans = 0
print(int(ans))