#include <bits/stdc++.h>
using namespace std;
int dp[100005];
int main(void) {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < (N); ++i) cin >> a[i];
  for (int i = 0; i < (N); ++i) {
    for (int j = 0; j < (100005); ++j) {
      dp[j] += (j % a[i]);
    }
  }
  int ans = 0;
  for (int i = 0; i < (100005); ++i) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
