#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
// #define MOD 998'244'353
// #define MOD 1'000'000'007
#define INF 100'000'000'000'000'000
using namespace std;
// using namespace atcoder;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    ll A[N+1];
    rep1(i, N) cin >> A[i]; // A[0]は使わない

    ll sum[N+1];
    sum[0] = 0;
    for(int i = 1; i <= N; i++){
        sum[i] = sum[i-1] + A[i];
    }

    ll sumsum[N+1];
    ll maxsumsum[N+1];
    sumsum[0] = sum[0];
    maxsumsum[0] = sumsum[0];
    for(int i = 1; i <= N; i++){
        sumsum[i] = sumsum[i-1] + sum[i];
    }

    maxsumsum[N-1] = sumsum[N-1];
    for(int i = N - 2; i >= 0; i--){
        maxsumsum[i] = max(maxsumsum[i+1], sumsum[i]);
    }
    // for(int i = 2; i < N; i++){
    //     maxsumsum[i] = max(maxsumsum[i-1], sumsum[i-1]);
    //     // cout << i << sumsum[i] << " : " << maxsumsum[i] << endl;
    // }



    ll ans = -INF;

    ll temp;
    for(int i = 1; i <= N; i++){
        temp = sumsum[i];
        // cout << temp << endl;
        temp += (maxsumsum[i-1] - sumsum[i-1]);
        if (temp > ans){
            ans = temp;
        }
        // cout << i << " : " << temp << endl;
    }

    if (ans < 0) ans = 0;

    cout << ans << endl;

    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end() 
using ll = long long;
int mod = 1000000007;
const int INF = 1001001001;
template<class T> void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> void chmax(T& a, T b) {if (a < b) a = b;}
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using Graph = vector<vector<int>>;


int main() {
    string n; cin >> n ;
    ll x = n.size();
    if (x % 2 == 1) {
        ll oans = 0; 
        ll y = x / 2;
        rep(i,y) {
            oans += 9 * pow(10, i);
        }
        cout << oans << endl;
        return 0;
    }
    ll A = 0, B = 0;
    for (int i = 0; i < x/2; i++) {
        A += (n[i] - '0') * pow(10, x/2-1-i);
    }
    for (int i = 0; i < x/2; i++) {
        B += (n[x/2+i] - '0') * pow(10, x/2-1-i);
    }
    if (A > B) cout << A - 1 << endl;
    else cout << A  << endl;
    return 0;
}



