#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long temp = a[0];
  for (long long i = 1; i < n; i++) {
    if (temp > a[i]) {
      temp += temp - n;
    } else {
      temp = a[i];
    }
  }
  cout << temp << '\n';
  return 0;
}
