import sys
N,M=[int(x) for x in input().rstrip().split()]

l=[-1 for i in range(N)]
ans=""
flag=1

for i in range(M):
  s,c=[int(x) for x in input().rstrip().split()]
  if l[s-1]==-1 or l[s-1]==c:
    l[s-1]=c
  else:
    flag=0
    break

if flag==1:
  for i in range(len(l)):
    if l[i]==-1:
      l[i]=0

if flag==1:
  if len(l)!=1 and l[0]!=0:
    for i in range(len(l)):
      ans+=str(l[i])
    print(ans)
  else:
    print(-1)
    
else:
  print(-1)
