/ /and$s{$`}=$y+=!${$'}++for($w,$h,@a)=<>;print$w*$y-$#a+($h-$y)*keys%s