#include<bits/stdc++.h>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define all_(x) x.begin() + 1, x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n; cin >> n;
vi vt(n);
for(int &x : vt) cin >> x;
ll l = 0, r = *max_element(all(vt));
ll m = r;
// 左右开区间写法
auto check = [&](ll start) -> bool {
for(int &x : vt) {
start += start - x;
if(start < 0) return false;
else if(start >= m) return true;
}
return true;
};
// 二分答案
while(r > l + 1) {
ll mid = (l + r) >> 1;
((check(mid)) ? r : l) = mid;
}
cout << r << endl;
return 0;
}