#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
long long x;
struct P {
  long long x, y;
  P(long long _x = 0, long long _y = 0) { x = _x, y = _y; }
};
bool operator<(P a, P b) {
  if (a.x == b.x) return a.y < b.y;
  return a.x < b.x;
}
multiset<P> s;
multiset<P>::iterator it;
P d[N * 60];
int d0;
void ins(P a) {
  if (s.size() && (*--s.end()).x >= a.x) {
    P b = *s.lower_bound(a);
    if (b.y >= a.y) return;
  }
  while (s.size() && (*s.begin()).x <= a.x) {
    P b = *--s.upper_bound(a);
    if (b.y > a.y) break;
    s.erase(b);
  }
  s.insert(a);
}
int main() {
  scanf("%d", &n);
  scanf("%lld", &x);
  s.insert(P(x - 1, 0));
  for (int i = 2, _b = n; i <= _b; i++) {
    scanf("%lld", &x);
    d0 = 0;
    for (it = --s.end();; it--) {
      P a = *it;
      if (a.x < x) break;
      d[++d0] = a;
      if (it == s.begin()) break;
    }
    for (int j = 1, _b = d0; j <= _b; j++) s.erase(d[j]);
    for (int j = 1, _b = d0; j <= _b; j++) {
      long long v = d[j].x / x;
      ins(P(d[j].x % x, d[j].y + v * x * (i - 1)));
      ins(P(x - 1, d[j].y + (v - 1) * x * (i - 1)));
    }
  }
  long long ans = 0;
  for (it = s.begin(); it != s.end(); it++) {
    P a = *it;
    ans = max(ans, a.y + a.x * n);
  }
  printf("%lld\n", ans);
}
