N,M=map(int,input().split())
d={}
for i in range(M):
  s,t=map(int,input().split())
  if s in d:
    if d[s]!=t:
      print('-1')
      exit()
  if s==1:
    if t==0:
      print('-1')
      exit()
  
  d[s]=t
if N==1:
    if s==1:
      if t==0:
        print('0')
        exit()
if 1 not in d:
  d[1]=1
for i in range(2,N):
  if i not in d:
    d[i]=0
L=[]
for i in d.values():
  L.append(str(i))
print(''.join(L))