How Does Descartes Arrive At His First Principle Through Methodological Doubt?

How Does Descartes Arrive At His First Principle Through Methodological Doubt? how did he arrive at this principle by first doubting everything? “I think, therefore I am.” He would reject all opinions in which he could suppose the least ground for doubt. How does Descartes use the method of doubt? In order to achieve this