Given a prime number $p$ and an integer $0<a_0<p$. Consider a sequence $a_i=p \mod a_{i-1}$, where $p$ is a prime number, how. How to estimate the smallest $i$ where $a_i=1$? $a_0$ is a positive integer and is guaranteed to be less than $p$.
I
I tried some prime numbers, and found that such $i$ is always small. I have never found an $i$ larger than 50 when $p$ is smaller than $10^7$. How to estimate the upper bound of $i$?