#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long arr[n + 1];
  long long mn = INT_MAX;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    mn = min(mn, arr[i]);
  }
  int mn_mn_pos = -1, mx_mn_pos = -1;
  for (int i = 0; i < n; ++i) {
    if (arr[i] == mn && mn_mn_pos == -1) {
      mn_mn_pos = i;
      mx_mn_pos = i;
    }
    if (arr[i] == mn) mx_mn_pos = i;
  }
  long long a = 0LL;
  for (int i = 0; i < n; ++i) {
    a += mn;
  }
  int c = 0, size = 0;
  for (int i = 0; i < n;) {
    size = 0;
    if (arr[i] != mn) {
      while (i < n && arr[i] != mn) {
        i++;
        size++;
      }
      c = max(c, size);
    } else {
      i++;
    }
  }
  size = n - 1 - (mx_mn_pos);
  size += mn_mn_pos;
  c = max(c, size);
  a += c;
  cout << a << '\n';
}
