Recursively solve for only valid input