Consider a sequence $a_i=p \mod a_{i-1}$, where $p$ is a prime number, 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 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$?