N,M=map(int,input().split())
b=[list(map(int,input().split())) for i in range(M)]
import sys
lists=[]
for i in range(N):
  lists.append(0)
try:
  for i1 in range(0,M):
    for i2 in range(i1,M):
      if b[i1][0]==b[i2][0] and b[i1][1]!=b[i2][1]:
        print (-1)
        sys.exit()
      else:
        lists[b[i1][0]-1]=b[i1][1]
except IndexError:
  print (-1)
  sys.exit()
for i3 in range(M):
  if b[i3][0]==1 and b[i3][1]==0:
    print (-1)
    sys.exit()
s=0
for i in range(N):
  s=s+lists[i]*10**(2-i)
if s>=10**N:
  print (-1)
elif s<10**(N-1):
  s=s+10**(N-1)
  print (s)
else:
  print (s)