#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const int MAXN = 2000228;
const ll INF = (1ll << 50);
set<pair<ll, ll>> s;
void ins(ll x, ll y) {}
int main() {
  ios_base::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(20);
  cout.tie(nullptr);
  cin.tie(nullptr);
  int n;
  cin >> n;
  ll p = INF;
  s.emplace(p - 1, 0);
  for (int i = 0; i < n; ++i) {
    ll x;
    cin >> x;
    if (x >= p) {
      continue;
    }
    p = x;
    vector<pair<ll, ll>> rmed;
    while (!s.empty()) {
      auto val = *s.rbegin();
      if (val.first < x - 1) {
        break;
      }
      s.erase(val);
      rmed.push_back(val);
    }
    pair<ll, ll> tmp{x, -1};
    s.emplace(tmp);
    ll last = 0;
    for (auto& val : rmed) {
      ll dv = val.first / x;
      last = max(last, val.second + x * (dv - 1) * i);
      ll md = val.first % x;
      ll nvl = x * dv * i + val.second;
      auto it = s.lower_bound(pair<ll, ll>{md, nvl});
      if (it->second >= nvl) {
        continue;
      }
      auto lit = it;
      while (lit != s.begin()) {
        auto nit = lit;
        --nit;
        if (nit->second > nvl) {
          break;
        }
        lit = nit;
      }
      s.erase(lit, it);
      s.emplace(md, nvl);
    }
    while (!s.empty() && s.rbegin()->second <= last) {
      auto it = s.end();
      --it;
      s.erase(it);
    }
    s.emplace(x - 1, last);
  }
  ll ans = 0;
  for (auto& val : s) {
    ans = max(ans, val.first * n + val.second);
  }
  cout << ans << "\n";
}
