N,M=list(map(int,input().split()))
ans_str='0'*N
flg=0
for i in range(M):
  a,b=list(map(int,input().split()))
  if(ans_str[a-1]!='0' and ans_str[a-1]!=str(b)):
    print(-1)
    flg=1
    break
  ans_str=ans_str[:a-1]+str(b)+ans_str[a:]
ans_int=int(ans_str)
if(flg==0):
  if(len(str(ans_int))==N):
    print(ans_int)
  else:
    print(-1)
  