#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long fact(long long n) { return !n ? 1 : n * fact(n - 1); }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  vector<int> v{8, 4, 2, 6};
  if (n == 0)
    cout << 1 << "\n";
  else {
    n = (n - 1) % 4;
    cout << v[n] << "\n";
  }
  return 0;
}
