#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, x, pos = 1, y = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x;
    if (x < pos) {
      y += n + 1 - pos;
      pos = 1;
    }
    y += x - pos;
    pos = x;
  }
  cout << y << endl;
  return 0;
}
