#include <stdio.h>
int main()
{
int n, m;
long long Count=0;
scanf("%d%d", &n, &m);
int cur, pre=1;
while(m--)
{
scanf("%d", &cur);
if(cur>pre)
Count+=cur-pre;
else if(cur<pre)
Count+=(n-pre)+1+(cur-1);
pre=cur;
}
printf("%I64d\n", Count);
return 0;
}
posted on
浙公网安备 33010602011771号