#include "bits/stdc++.h"
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    long long a[n];
    long long mx = 0;
    long long sum = 0;
    long long mospos = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i) a[i] += a[i - 1];
        mospos = max(a[i], mospos);
        mx = max(sum + mospos, mx);
        sum += a[i];
    }
    cout << mx << endl;
}


/*
ID: Λινδα
LANG: C++
TASK: abc196c
*/
#include <stdio.h>
long long ppct(long long x)
{
	long long i=0,s=1;
	do
	{
		x=x/10;
		i++;
	}
	while(x!=0);
	while(i--)
	{
		s=s*10;
	}
	return s;
}
int read(){char c=getchar();int t=0,f=1;while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){t=(t<<1)+(t<<3)+(c^48);c=getchar();}return t*f;}
void write(int x){char ch[50];int l=0;if(x<0){putchar('-');x=-x;}do{ch[l++]=x%10+'0';x=x/10;}while(x);while(l){putchar(ch[--l]);}}
int main()
{
//	freopen("main.in","r",stdin);
//	freopen("main.out","w",stdout);
//	freopen("main.err","w",stderr);
	long long i=1,n,s=0;
	scanf("%lld",&n);
	while(i*ppct(i)+i<=n)
	{
//		printf("%lld ",i*ppct(i)+i);
		s++;
		i++;
	}
	printf("%lld\n",s);
//	fclose(stdin);
//	fclose(stdout);
//	fclose(stderr);
	return 0;
}