#include <bits/stdc++.h>
using namespace std;
long long mypow(long long x, long long y)
{
	long long result = 1;
	while (y != 0) {
		if (y%2 != 0) {
			result *= x;
			y -= 1;
		}	
		x *= x;
		y /= 2;
	}
	return result;
}
int main(void)
{
	int n;
	cin >> n;
	int a[n];
	vector<pair<int, int>> v;
	int x;
	int y = -1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i == 0) {
			x = a[i];
		} else {
			if (i == n-1) {
				if (y != -1 && x < y)
					v.push_back(make_pair(x, y));
			} else {
				if (a[i-1] > a[i]) {
					if (y != -1) {
						v.push_back(make_pair(x, y));
					}
					x = a[i];
				} else {
					y = a[i];
				}
			}
		}
	}
	for (auto e : v) {
		//printf("%d, %d\n", e.first, e.second);
		long long tmp = money / (long long)e.first;
		money = money - tmp*(long long)e.first + tmp*(long long)e.second;
	}
	cout << money << endl;
	return 0;
}