#include<iostream>
using namespace std;
int main()
{
long long n, m;
cin >> n >> m;
long long temp, total = 0,last_position=1;
while (m--){
cin >> temp;
total += (temp >= last_position) ? (temp - last_position) : (n - (last_position - temp));
last_position = temp;
}
cout << total << endl;
return 0;
}
CodeForces-339B-Xenia and Ringroad
最新推荐文章于 2020-07-22 14:44:00 发布