#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n;
long long f[N], a[N];
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = n; i; i--) cin >> a[i];
  for (int i = n - 1; i; i--) a[i] = min(a[i], a[i + 1]);
  a[0] = 1;
  for (int i = (1); i <= (n); i++)
    for (long long j = a[i], k, l = 0; j; j %= a[k]) {
      k = lower_bound(a + 1, a + n + 1, j) - a - 1;
      f[i] = max(f[i], f[k] + (n - k) * (j - j % a[k] - a[k]) + l);
      l += (n - k) * (j - j % a[k]);
    }
  cout << f[n] << endl;
  return 0;
}
