#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int input() {
	int r;
	scanf("%lld", &r);
	return r;
}
signed main() {
	int n;
	while (n = input()) {
		int ans = n * n * n;
		for1(i, n)for1(j, n) {
			if (i * i * i + j * j * j > n * n * n)continue;
			ans = min(ans, n * n * n - i * i * i - j * j * j);
		}
		cout << ans << endl;
	}
}
