#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int main() {
   int N;
   cin >> N;
   vector<int> a(N,0);
   rep(i,N) cin >> a.at(i);
   int max = max_element( a.begin(), a.end() );
   vector<int> f(max,0);
   rep(m,max){
     rep(j,N) f.at(m) += m % a.at(j);
   }
   cour << max_element( f.begin(), f.end() ) << endl;
}