#include <bits/stdc++.h>
using namespace std;
long long n;
vector<pair<long long, long long>> a;
int dis(long long f, long long s) {
  if (f < s) return s - f;
  if (f > s) return (n - f) + s;
  return 0;
}
int main() {
  scanf("%I64d", &n);
  long long c;
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &c);
    a.push_back(make_pair(c, i + 1));
  }
  sort(a.begin(), a.end());
  long long m = a[0].first;
  long long k = 0;
  long long maxd = 0;
  long long last = -1, first;
  for (auto i : a) {
    if (i.first == m) {
      if (last == -1) {
        last = i.second;
        first = last;
      } else {
        maxd =
            ((maxd) > (dis(last, i.second)) ? (maxd) : (dis(last, i.second)));
        last = i.second;
      }
      k++;
      continue;
    }
    if (i.first > m)
      if (maxd == 0) maxd = n;
    if (last != first)
      maxd = ((maxd) > (dis(last, first)) ? (maxd) : (dis(last, first)));
    break;
  }
  if (maxd != 0) maxd--;
  long long ret = n;
  ret *= m;
  ret += maxd;
  cout << ret;
}
