#include<iostream>
#include<algorithm>
using namespace std;
int main(){

	long long int A[5001]={0};
	long long int n,MAX = -100000;

		while(1){

			cin >> n;

			if( n == 0 ) break;

			for(int i = 1; i <= n; i++){

				cin >> A[i];
	
			}

			MAX = -100000;
		
			for(int i = 1; i <= n; i++){

				A[i] = max(A[i], A[i] + A[i-1]);
				MAX = max(A[i], MAX);

			}
	
			cout  << MAX << endl;

		}
	return 0;
}
// 2016-12-05
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int e, x, y, z, m;
	while (cin >> e, e) {
		m = 1000000;
		for (z = 0; z * z * z <= e; z++) {
			y = (int)sqrt(e - z * z * z);
			x = e - z * z * z - y * y;
			m = min(m, x + y + z);
		}
		cout << m << endl;
	}
	return 0;
}