Let $p$ be an odd prime. The sequence $(a_n)_{n \geq 0}$ is defined as follows: $a_0=0$, $a_1=1, \ldots, a_{p-2}=p-2$ and, for all $n \geq p-1$, $a_n$ is the least positive integer that does not form an arithmetic sequence of length $p$ with any of the preceding terms. Prove that, for all $n$, $a_n$ is the number obtained by writing $n$ in base $p-1$ and reading the result in base $p$.