/* Problem URL: https://codeforces.com/group/btcK4I5D5f/contest/601720/problem/F */

#include <bits/stdc++.h>

using namespace std;

#define V vector

#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)

#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)

#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;

using ll = long long;

using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;

template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
    os << vec[0];
    for (size_t i = 1; i < vec.size(); i++) {
        os << ' ' << vec[i];
    }
    os << '\n';
    return os;
}

template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
    for (auto &i : vec) {
        is >> i;
    }
    return is;
}

template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
    for (auto &i : vec) {
        os << i[0];
        for (size_t j = 1; j < i.size(); j++) {
            os << ' ' << i[j];
        }
        os << '\n';
    }
    return os;
}

template<class v>
auto operator>>(istream  &is, vector<vector<v>> &vec)->istream& {
    for (auto &i : vec) {
        for (auto &j : i) {
            is >> j;
        }
    }
    return is;
}

ll fact(ll n)
{
    if (n == 1) {
        return n;
    }
    return n * fact(n - 1);
}

ll fastpow(ll n, ll p)
{
    ll ans = 1;
    ll power = n % 10;

    for (size_t i = 0; i <= 100; i++) {
        if (p & ((__int128)1 << i)) {
            ans *= power;
            ans %= 10;
        }
        power *= power;
        power %= 10;
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll no;
    cin >> no;
    __int128 n = no;

    __int128 n2 = 0;
    __int128 n3 = 0;
    __int128 n4 = 0;
    __int128 n5 = 0;
    __int128 n6 = 0;
    __int128 n7 = 0;
    __int128 n8 = 0;
    __int128 n9 = 0;
    for (__int128 i = 10; i <= n * (__int128)10; i *= 10) {
        if (n / (i / 10) % 10 >= 2) {
            n2 += n / i + 1;
        } else {
            n2 += n / i;
        }
        if (n / (i / 10) % 10 >= 3) {
            n3 += n / i + 1;
        } else {
            n3 += n / i;
        }
        if (n / (i / 10) % 10 >= 4) {
            n4 += n / i + 1;
        } else {
            n4 += n / i;
        }
        if (n / (i / 10) % 10 >= 5) {
            n5 += n / i + 1;
        } else {
            n5 += n / i;
        }
        if (n / (i / 10) % 10 >= 6) {
            n6 += n / i + 1;
        } else {
            n6 += n / i;
        }
        if (n / (i / 10) % 10 >= 7) {
            n7 += n / i + 1;
        } else {
            n7 += n / i;
        }
        if (n / (i / 10) % 10 >= 8) {
            n8 += n / i + 1;
        } else {
            n8 += n / i;
        }
        if (n / (i / 10) % 10 >= 9) {
            n9 += n / i + 1;
        } else {
            n9 += n / i;
        }
    }

    // cout << n2 << ' ' << n3 << ' ' << n4 << ' ' << n5 << ' ' << n6 << ' ' << n7 << ' ' << n8 << ' ' << n9 << '\n';

    n5 = 0;
    for (__int128 i = 5; i <= n; i *= 5) {
        for (__int128 j = 1; i * j <= n; j *= 10) {
            __int128 tmp = n / (i * j);

            // n2 += tmp / 10;
            // if (tmp % 10 >= 2) {
            //     n2++;
            // }
            n3 += tmp / 10;
            if (tmp % 10 >= 3) {
                n3++;
            }
            // n4 += tmp / 10;
            // if (tmp % 10 >= 4) {
            //     n4++;
            // }
            n6 += tmp / 10;
            if (tmp % 10 >= 6) {
                n6++;
            }
            n7 += tmp / 10;
            if (tmp % 10 >= 7) {
                n7++;
            }
            // n8 += tmp / 10;
            // if (tmp % 10 >= 8) {
            //     n8++;
            // }
            n9 += tmp / 10;
            if (tmp % 10 >= 9) {
                n9++;
            }
        }
        n5 += n / i;
    }

    for (__int128 i = 10; i <= n; i *= 10) {
        n5 -= n / i;
    }

    // cout << n2 << ' ' << n3 << ' ' << n4 << ' ' << n5 << ' ' << n6 << ' ' << n7 << ' ' << n8 << ' ' << n9 << '\n';
    n2 -= n5;
    if (n2 < 0) {
        ll diff = -n2;
        n2 = diff;
        n4 -= diff;
    }
    // n2 += n10;
    // cout << n2 << ' ' << n3 << ' ' << n4 << ' ' << n5 << ' ' << n6 << ' ' << n7 << ' ' << n8 << ' ' << n9 << '\n';
    ll ans = fastpow(2, n2);
    ans %= 10;
    ans *= fastpow(3, n3);
    ans %= 10;
    ans *= fastpow(4, n4);
    ans %= 10;
    ans *= fastpow(6, n6);
    ans %= 10;
    ans *= fastpow(7, n7);
    ans %= 10;
    ans *= fastpow(8, n8);
    ans %= 10;
    ans *= fastpow(9, n9);
    ans %= 10;
    cout << ans << '\n';
}
