#include <bits/stdc++.h>
using namespace std;
int f(int m, int a) { return m % a; }
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < a[n - 1]; i++) {
    int res = 0;
    for (int m = 0; m < a[n - 1]; m++) {
      res += f(m, a[i]);
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}
