#include <bits/stdc++.h>
using namespace std;
int n;
long long a[220000];
map<long long, long long> b[220000];
inline int get(int p, long long r) {
  int lo = p, hi = n + 1;
  while (hi - lo > 1) {
    int mid = lo + hi >> 1;
    if (a[mid] > r)
      lo = mid;
    else
      hi = mid;
  }
  return hi;
}
inline void chkmax(long long &a, long long b) {
  if (a < b) a = b;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (i > 1 && a[i] > a[i - 1]) a[i] = a[i - 1];
  }
  a[n + 1] = 1;
  b[1][a[1] - 1] = 0;
  for (int p = 1; p <= n; p++) {
    for (auto &t : b[p]) {
      long long r = t.first;
      long long B = t.second;
      if (a[p] > r) {
        chkmax(b[get(p, r)][r], B);
      } else {
        long long rr = r % a[p];
        long long BB;
        if (rr < a[p] - 1) {
          BB = B + (p - 1) * (r - rr);
          chkmax(b[get(p, rr)][rr], BB);
        }
        BB = B + (p - 1) * (r + 1 - (rr + 1) % a[p] - a[p]);
        chkmax(b[get(p, a[p] - 1)][a[p] - 1], BB);
      }
    }
  }
  long long ans = 0;
  for (auto &t : b[n + 1]) chkmax(ans, t.first * n + t.second);
  cout << ans << endl;
  return 0;
}
