#include <stdio.h>

int power( int, int );

int main( void ) {
	int i, power2[ 1001 ], power3[ 101 ], e, ee, x, y, z, min;

	for ( i = 0; i < 1001; i++ )
		power2[ i ] = power( i, 2 );
	for ( i = 0; i < 101; i++ )
		power3[ i ] = power( i, 3 );

	while ( scanf( "%d", &e ), e ) {
		min = e;
		for ( z = 0; power[ z ] <= e; z++ ) {
			ee = e - power[ z ];

			for ( y = 0; power[ y ] <= ee; y++ ) {
				x = ee - power[ y ];

				if ( x + y + z < min )
					min = x + y + z;
			}
		}

		printf( "%d\n", min );
	}

	return 0;
}

int power( int x, int n ) {
	int tmp = 1;

	while( n-- )
		tmp *= x;

	return tmp;
}