#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, nn, ans = 0, nans;
  cin >> n;
  long long a[n + 2];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    while (a[i + 1] == a[i]) {
      i++;
    }
    nn = a[i] + (a[i] - 1);
    nans = 0;
    for (j = 0; j < n; j++) {
      nans += (nn % a[j]);
    }
    if (nans > ans) {
      ans = nans;
    }
  }
  cout << ans << endl;
  return 0;
}
