import sys
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
for i in range(1000):
  x=list(str(i))
  ct=0
  for j in range(m):
    if len(x)>=l[j][0]:
      if x[l[j][0]-1]==str(l[j][1]):
        ct+=1
  if ct==m and len(x)==n:
    print(i)
    sys.exit()
print(-1)