Fast and exact search for the partition with minimal information loss