First implementation, use matrix first row and column as auxiliary storage