($n,$m)=<>=~/\d+/g;map{($a,$b,$c)=<>=~//g;push@{$c.-$a},$b,push@{$c.-$b},$a,0}1..$m;@a=1..$n;<>=~s//@a=sort{$a-$b}keys{map@{$&.-$_},@a}/ger;print@a." @a"