<?php
fscanf(STDIN,"%d %d",$n,$m);
//echo $n," ",$m,"\n";
for ($i = 0; $i < $m; $i++) {
    fscanf(STDIN,"%d %d",$s[$i],$c[$i]);
    if ($s[$i]==1 and $c[$i]==0) {
        echo -1,"\n";
        exit();
    }
}

?>
