#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<pair<int, int>> mi(n);
  mi[n - 1] = {a[n - 1], n - 1};
  for (int i = n - 2; i >= 0; --i) {
    mi[i] = {a[i], i};
    amin(mi[i], mi[i + 1]);
  };
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    long long tmp = (n - i);
    int t = 0, ix = -1;
    if (mi[i].first - 1 < mi[0].first) {
      t = mi[i].first - 1;
      ix = mi[i].second;
    } else {
      t = mi[0].first;
      ix = mi[0].second;
    }
    tmp += t * 1ll * n + (ix - 0);
    ;
    ans = max(tmp, ans);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
