solved. first I create a data structure with all permutations of the input data, then I create Date's for each one, and check if it is valid, then I choose the minimum Date and return it