#include<bits/stdc++.h>
#define MAX 1000005
using namespace std;
bool check[MAX];
vector<int>primes;
int n,cntTwo,cntFive;
long long res;
void sieve()
{
int i,j;
primes.push_back(2);
for(i=3; i<=1000; i+=2)
{
for(j=i*i; j<MAX; j+=2*i)
{
check[j] = true;
}
}
for(i=3; i<MAX; i+=2)
{
if(check[i]==false)
{
primes.push_back(i);
}
}
}
void solve()
{
cntTwo = 0;
cntFive = 0;
res = 1;
for(int i=0; primes[i]<=n; i++)
{
long long temp = 1;
if(primes[i]==2)
{
while(temp*2<=n)
{
cntTwo++;
temp*=2;
}
}
else if(primes[i]==5)
{
while(temp*5<=n)
{
cntFive++;
temp*=5;
}
}
else
{
while(temp*primes[i]<=n)
{
temp*=primes[i];
res*=primes[i];
res%=10;
}
}
}
}
int main()
{
sieve();
int i;
while(scanf("%d",&n)&&n)
{
solve();
for(i=1; i<=cntTwo-cntFive; i++)
{
res*=2;
res%=10;
}
printf("%lld\n",res);
}
return 0;
}