n,m=map(int,input().split())
c=[list(map(int,input().split())) for i in range(m)]
if [1,0] in c and n>1:
  print(-1)
  exit()
num=[1]+[0]*(n-1)
try:
  for i in c:
  	num[i[0]-1]=i[1]
except:
  print(-1)
  exit()
for i in c:
  if num[i[0]-1]!=i[1]:
    print(-1)
    exit()
print(int("".join(map(str,num))))