n,m=map(int,input().split())
jouken=[]
for x in range(m):
  jouken.append(list(map(int,input().split())))

for x in range(10**n):
  ans=0
  xx=str(x)
  if not len(xx)==n:
    continue
  for y in range(m):
    a=jouken[y][0]-1
    b=jouken[y][1]
    
    
    if not int(xx[a])==b:
      ans+=1
    
  if ans==0:
    print(x)
    break

if ans>1:
  print(-1)

