#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d, e, cnt = 1, snt = 0, f;
string s, n, s1;
vector<int> v;
char u;
int main() {
  cin >> a;
  if (a == 0) {
    cout << "1";
    return 0;
  }
  a %= 4;
  if (a == 0)
    cout << "6";
  else if (a == 1)
    cout << "8";
  else if (a == 2)
    cout << "4";
  else if (a == 3)
    cout << "2";
}
