N,M=map(int,input().split())
li=[list(map(int,input().split())) for _ in range(M)]
zero=["0"]*N
for i in range(M):
  order=li[i][0]-1
  try:
    zero[order]=li[i][1]
  except:
    print(-1)
    exit()
a=[str(s) for s in zero]
a2="".join(a)
a3=int(a2)
a4=str(a3)
if len(a2)!=len(a4):
  print(-1)
  exit()
print(a2)