Think about recursive algoritm.