#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  long long i;
  int result = 1;
  cin >> n;
  if (n == 0) {
    result = 1;
  } else if (n % 4 == 1) {
    result = 8;
  } else if (n % 4 == 2) {
    result = 4;
  } else if (n % 4 == 3) {
    result = 2;
  } else if (n % 4 == 0) {
    result = 6;
  }
  cout << result;
  return 0;
}
