Codeforces 339B

#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;
}

  

猜你喜欢

转载自www.cnblogs.com/commario/p/11803861.html