NR==1{N=$1; M=$2}
NR>1{s[NR-1]=$1; c[NR-1]=$2;
	if((d[$1] && d[$1]!=$2) ||
       (N>1 && $1==1 && $2==0)){
    	print "-1";
        flag_end = 1;
        exit;
    }
    d[$1]=$2;
}
END{
	if(flag_end)exit;
    for(i=1;i<=N;i++){
    	if(i==1)tmp = 1;
        else tmp = 0;
		for(k=1;k<=M;k++){
        	if(i==s[k]){
            	tmp = c[k];
            }
        }
        ans = ans tmp;
    }
    ans += 0;
    keta = int(log(ans)/log(10));
    if(keta > N && ans != 0){print -1; exit}
    if(ans == 0 && N != 1){print -1; exit}
    print ans;
}