import sys

N, M = (int(x) for x in input().split())
num=[0]*N
check=[False]*N

for i in range(M):
  s,c=(int(x) for x in input().split())
  if s==1 and c==0:
    print(-1)
    sys.exit(0)
  if check[s-1]==False:
    num[s-1]=c
    check[s-1]=True
  elif check[s-1]==True and num[s-1]!=c:
    print(-1)
    sys.exit(0)
if num[0]==0:
  num[0]=1
print(*num,sep="")