12
 1378
 51202278
 989898989
 4
 7
 9
 6
 8
 12193721
 999999995
 999999999
 11
 999999996
 999999998
 3
 14
 15
 10
 999999994
 1000
 13781378
 5
 999999997
 1000000000
 13
 16
 0

6
 4
 4
 8
 6
 2
 8
 4
 6
 8
 2
 2
 2
 6
 4
 2
 4
 2
 4
 4
 6
 4
 8
 8
 6
 8
 6
 1

#include <bits/stdc++.h>
using namespace std;
const int NN = 50010;
const int INF = 0x3f3f3f3f;
const int MOD = 100000, STA = 8000010;
const long long LNF = 1LL << 60;
const double EPS = 1e-8;
const double OO = 1e15;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int sign(double x) { return (x > EPS) - (x < -EPS); }
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
inline T lcm(T a, T b, T d) {
  return a / d * b;
}
template <class T>
inline T Min(T a, T b) {
  return a < b ? a : b;
}
template <class T>
inline T Max(T a, T b) {
  return a > b ? a : b;
}
template <class T>
inline T Min(T a, T b, T c) {
  return min(min(a, b), c);
}
template <class T>
inline T Max(T a, T b, T c) {
  return max(max(a, b), c);
}
template <class T>
inline T Min(T a, T b, T c, T d) {
  return min(min(a, b), min(c, d));
}
template <class T>
inline T Max(T a, T b, T c, T d) {
  return max(max(a, b), max(c, d));
}
int N, M, T;
int main() {
  cin >> N;
  if (N == 0) cout << 1 << endl;
  if (N % 4 == 0)
    cout << 6 << endl;
  else if (N % 4 == 1)
    cout << 8 << endl;
  else if (N % 4 == 2)
    cout << 4 << endl;
  else if (N % 4 == 3)
    cout << 2 << endl;
  return 00;
}
