The very first thing you do is put your computer aside, get some paper and a pen, and begin planning how you want to approach this.

Think about the logic you will need to solve this problem. Figure out the list of steps you must follow in order to solve this problem "on paper". When you have a list of steps, then you can start converting it into code.

Programming is about problem-solving. Working through these steps to come up with an algorithm on your own is an important skill to learn.

Start thinking of how you might go about solving this problem "by hand", and see what you come up with.