include[HTML_REMOVED]
using namespace std;
define N 100010
int n;
int H[N];
bool check(int E)
{
for (int i = 1; i <= n; i)
{
E = 2*E - H[i];
if (E >= 1e5)
return true;
if (E < 0)
{
return false;
break;
}
}
return true;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i)
cin >> H[i];
int l = 0;
int r = 1e5;
while (l < r)
{
int mid = (l + r)/2;
if (check(mid))
r = mid;
else
l = mid + 1;
}
cout << l << endl;
return 0;
}