2
0 1
 1
0

1
2
 1

#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long tmp = 0, fl = 0;
  static char ch;
  while (ch = getchar(), ch < '0' || ch > '9') fl |= (ch == '-');
  tmp = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') tmp = tmp * 10 + (ch ^ 48);
  return fl ? -tmp : tmp;
}
int n;
long long ans = 0;
map<long long, long long> dp;
int main() {
  scanf("%d", &n);
  long long a = read();
  dp[a - 1] = 0;
  for (int i = 2; i <= n; i++) {
    a = read();
    for (map<long long, long long>::iterator j = dp.lower_bound(a);
         j != dp.end(); dp.erase(j++)) {
      long long j_ = j->first, w_ = j->second;
      dp[j_ % a] = max(dp[j_ % a], w_ + (i - 1) * (j_ - j_ % a));
      dp[a - 1] = max(dp[a - 1], w_ + (i - 1) * ((j_ + 1) / a * a - a));
    }
  }
  for (map<long long, long long>::iterator j = dp.begin(); j != dp.end(); j++) {
    long long j_ = j->first, w_ = j->second;
    ans = max(ans, n * j_ + w_);
  }
  printf("%lld\n", ans);
}
