#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  if (n == 0)
    n = 1;
  else if (n % 4 == 1)
    n = 8;
  else if (n % 4 == 2)
    n = 4;
  else if (n % 4 == 3)
    n = 2;
  else
    n = 6;
  cout << n << "\n";
  return 0;
}
