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 long long mod = 1000000007;
template <class T>
void read(T &a) {
  cin >> a;
}
template <class T1, class T2>
void read(T1 &a, T2 &b) {
  cin >> a >> b;
}
template <class T1, class T2, class T3>
void read(T1 &a, T2 &b, T3 &c) {
  cin >> a >> b >> c;
}
template <class T>
void read(T *a, int size) {
  for (int i = 0; i < size; i++) {
    read(a[i]);
  }
}
void read(vector<int> v, int size) {
  for (int i = 0; i < size; i++) cin >> v[i];
}
template <class T>
void print(T a) {
  cout << a;
}
template <class T>
void print(T *a, int size) {
  for (int i = 0; i < size; i++) {
    print(a[i]);
    print("\n");
  }
}
void print(int *a, int size) {
  for (int i = 0; i < size; i++) {
    print(a[i]);
    print("\n");
  }
}
void solve() {
  int n;
  read(n);
  int a[] = {8, 4, 2, 6};
  if (n == 0)
    cout << 1;
  else {
    n = n % 4;
    if (n == 0) n = 4;
    cout << a[n - 1];
  }
}
int main() {
  int t = 1;
  for (int i = 0; i < t; i++) solve();
  return 0;
}
