SPOJ Find Min Cost in Matrix