N,M=map(int,input().split())
sc=[]
for i in range(M):
  s,c=map(int,input().split())
  sc.append((s,c))
sc=set(sc)
sc=list(sc)
m=len(sc)
if M==0:
  if N==1:
    print(0)
  else:
    print(10**(N-1))
else:
  flag=0
  for i in range(m):
    if sc[i][0]==1:
      if sc[i][1]==0:
        flag=1
        break
      else:
        flag=2
        break
  for i in range(m-1):
    for j in range(i+1,m):
      if sc[i][0]==sc[j][0]:
        flag=1
        break
  if flag==1:
    print(-1)
  elif flag==2:
    x=0
    for i in range(m):
      x=x+(sc[i][1]*10**(N-sc[i][0]))
    print(x)
  elif flag==0:
    x=10**(N-1)
    for i in range(m):
      x=x+(sc[i][1]*10**(N-sc[i][0]))
    print(x)