#include<stdio.h>
int x,y,z,r;
int t(int t){return t*t*t;}
int main()
{
	for(;scanf("%d",&z),z;)
	{
		z=t(z);
		r=1000000000;
		for(x=1;t(x)<=z;x++)
			for(y=1;t(x)+t(y)<=z;y++)
			{
				r=r>z-(t(x)+t(y))?z-(t(x)+t(y)):r;
			}
		printf("%d\n",r);
	}
	return 0;
}