#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  scanf("%I64d", &n);
  int tem = n % 4;
  if (tem == 1) {
    cout << "8" << endl;
  }
  if (tem == 0) {
    if (n == 0)
      cout << "1" << endl;
    else
      cout << "6" << endl;
  }
  if (tem == 3) {
    cout << "2" << endl;
  }
  if (tem == 2) {
    cout << "4" << endl;
  }
}
