We are given $n, m$, with $2 \leq n \leq 10^5, 1 \leq m \leq 10^5$, and told to compute the total time to complete $m$ tasks. Each task $a_i$, for $1 \leq i \leq m$ must be completed at location $a_i$, and we are initially at location $1$. Time is accumulated whenever you move from location $x$ to $x + 1$ (or if $x \equiv n$, then from $n$ to $1$).
Important thing to note is that you cannot move in either direction around the ring (something I assumed when I did this problem); only moving forwards. Once that is clear, the problem is easy.