import sys
N,M=map(int,input().split())
S=[]
for i in range(M):
  s=list(map(int,input().split()))
  S.append(s)
S.sort()
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
C=get_unique_list(S)
if len(C)>N:
  print(-1)
  sys.exit
for i in range(len(C)-1):
  if C[i][0]==C[i+1][0]:
    print(-1)
    sys.exit
ans=[]
for i in range(N):
  if C[i][0]==i+1:
  	ans.append(C[i][1])
  else:
    ans.append(0)
if ans[0]==0:
  ans[0]=1
for i in range(N):
  print(ans[i], end='')