text: /*************************************************************************
  >>> Author: WindCry1
  >>> Mail: lanceyu120@gmail.com
  >>> Website: https://windcry1.com
  >>> Date: 12/16/2019 12:56:54 PM
  *************************************************************************/
  #pragma GCC optimize(3)
  #include <cstring>
  #include <cmath>
  #include <cstdio>
  #include <cctype>
  #include <cstdlib>
  #include <ctime>
  #include <vector>
  #include <iostream>
  #include <string>
  #include <queue>
  #include <set>
  #include <map>
  #include <algorithm>
  #include <complex>
  #include <stack>
  #include <bitset>
  #include <iomanip>
  #include <list>
  #include <sstream>
  #include <fstream>
  #if __cplusplus >= 201103L
  #include <unordered_map>
  #include <unordered_set>
  #endif
  #define ll long long
  #define ull unsigned long long
  #define DEBUG(x) cout<<#x<<" : "<<x<<endl;
  using namespace std;
  typedef pair<int, int> pii;
  typedef pair<ll, ll> pll;
  const double clf = 1e-8;
  const int MMAX = 0x7fffffff;
  const int INF = 0x3f3f3f3f;
  const int mod = 1e9+7;
  const int dir[4][2]={-1,0,1,0,0,-1,0,1};
  ostream& operator <<(ostream &out, pii &p){
  	return out<<p.first<<" "<<p.second;
  }
  istream& operator >>(istream &in, pii &p){
  	return in>>p.first>>p.second;
  }
  vector<int> v;
  set<int> st;
  map<int,int> mp;
  int main(){
  	ios::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	//ifstream cin("C:\\Users\\LENOVO\\Desktop\\in.txt");
  	//ofstream cout("C:\\Users\\LENOVO\\Desktop\\out.txt");
  	ll n;
  	while(cin>>n) v.push_back(n),st.insert(n);
  	ll res=1;
  	for(int i=1;i<=50000000;i++)
      {
          res*=i;
          while(res%10==0)
              res/=10;
          res=res%100000000;
          if(st.count(i)){
          	mp[i]=res%10;
  		}
      }
  	for(auto i:v) cout<<mp[i]<<endl;
  	return 0;
  }
  
  