Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
- #define ll long long
- int main()
- {
- int a,b;
- fastread()
- cin>>a>>b;
- int ara[b+1];
- ll ans=0;
- for(int i=0; i<b; i++)
- {
- cin>>ara[i];
- if(i==0)
- {
- if(ara[i]>=1)
- {
- ans+=ara[i]-1;
- }
- else
- {
- ans+=a+ara[i]-1;
- }
- }
- else
- {
- if(ara[i]>=ara[i-1])
- {
- ans+=ara[i]-ara[i-1];
- }
- else
- {
- ans+=a+ara[i]-ara[i-1];
- }
- }
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement