#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
#define MAX 10001000
#define size 1000000
typedef long long ll;
ll prime[size], status[MAX];
ll factor[150];
ll p, d;
void siv()
{
ll n;
ll i, j;
n=MAX;
ll sq= sqrt(n);
for(i=3; i<=sq; i+=2)
{
if(status[i]==0)
{
for(j=i*i; j<=n; j+=(i+i))
{
status[j]=1;
}
}
}
prime[0]=2;
p=1;
for(i=3; i<=n; i+=2)
{
if(status[i]==0)
{
prime[p++] = i;
}
}
}
void primeFactor(ll n)
{
ll i, j, temp;
ll sq = ll(sqrt(n));
d=0;
temp =0;
for(i=0; prime[i]<=sq; i++)
{
while(n%prime[i]==0)
{
if(temp !=prime[i])
factor[d++] = prime[i];
n /= prime[i];
temp = prime[i];
}
}
if(n>1)
{
factor[d++] = n;
}
}
int main()
{
siv();
ll n;
while(cin >> n)
{
if(n==0) break;
if(n<0) n*=-1;
primeFactor(n);
if(d<2)
{
cout << "-1" << endl;
}
else
{
cout << factor[d-1] << endl;
}
}
return 0;
}
#include<iostream>
#include<cmath>
using namespace std;
#define MAX 10001000
#define size 1000000
typedef long long ll;
ll prime[size], status[MAX];
ll factor[150];
ll p, d;
void siv()
{
ll n;
ll i, j;
n=MAX;
ll sq= sqrt(n);
for(i=3; i<=sq; i+=2)
{
if(status[i]==0)
{
for(j=i*i; j<=n; j+=(i+i))
{
status[j]=1;
}
}
}
prime[0]=2;
p=1;
for(i=3; i<=n; i+=2)
{
if(status[i]==0)
{
prime[p++] = i;
}
}
}
void primeFactor(ll n)
{
ll i, j, temp;
ll sq = ll(sqrt(n));
d=0;
temp =0;
for(i=0; prime[i]<=sq; i++)
{
while(n%prime[i]==0)
{
if(temp !=prime[i])
factor[d++] = prime[i];
n /= prime[i];
temp = prime[i];
}
}
if(n>1)
{
factor[d++] = n;
}
}
int main()
{
siv();
ll n;
while(cin >> n)
{
if(n==0) break;
if(n<0) n*=-1;
primeFactor(n);
if(d<2)
{
cout << "-1" << endl;
}
else
{
cout << factor[d-1] << endl;
}
}
return 0;
}