死因:
wa在第七个点,因没开ll
/*
*date:2021-11-11
*author:percation
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 20;
ll n,m;
map<string, int> mp;
string s;
int a[N];
int k;
int main(){
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> a[i];
}
ll ans = 0;
for(int i = 0; i < m; i++){
if(i == 0){
ans += (1ll)*(a[i] - 1);
}
else{
if(a[i] - a[i - 1] >= 0){
ans += (1ll)*(a[i] - a[i - 1]);
}
else{
ans += (1ll)*(n + a[i] - a[i - 1]);
}
}
}
cout << ans << endl;
return 0;
}