#include <bits/stdc++.h>
using namespace std;
long long modular_pow(long long base, long long exponent, int modulus) {
  long long result = 1;
  while (exponent > 0) {
    if (exponent % 2 == 1) result = (result * base) % modulus;
    exponent = exponent >> 1;
    base = (base * base) % modulus;
  }
  return result;
}
int main() {
  long long x, y;
  int mod;
  cin >> y;
  cout << modular_pow(1378, y, 10);
  return 0;
}
