#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int first = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar()) {
    if (ch == '-') f = -1;
  }
  for (; isdigit(ch); ch = getchar()) {
    first = first * 10 + ch - 48;
  }
  return first * f;
}
const int mxN = 2e5;
int n;
long long a[mxN + 3];
map<long long, long long> f;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (i > 1) {
      a[i] = min(a[i], a[i - 1]);
    }
  }
  f[a[1] - 1] = 0ll;
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1]) {
      continue;
    }
    if (!f.count(a[i] - 1)) {
      f[a[i] - 1] = 0ll;
    }
    for (map<long long, long long>::reverse_iterator it = f.rbegin();
         (it->first) >= a[i]; it = f.rbegin()) {
      long long first = it->first, xx = first % a[i];
      f[a[i] - 1] = max(f[a[i] - 1], (it->second) + 1ll * (i - 1ll) * a[i] *
                                                        (first / a[i] - 1ll));
      f[xx] =
          max(f[xx], (it->second) + 1ll * (i - 1ll) * a[i] * (first / a[i]));
      f.erase(first);
    }
  }
  long long ans = 0ll;
  for (map<long long, long long>::iterator it = f.begin(); it != f.end();
       it++) {
    ans = max(ans, (it->first) * n + (it->second));
  }
  printf("%lld\n", ans);
  return 0;
}
