#include <bits/stdc++.h>
using namespace std;
int main() {
  int k = 8;
  int t = 4;
  int p = 2;
  int s = 6;
  int n;
  while (cin >> n) {
    if (n == 0)
      cout << 1 << endl;
    else if (n % 4 == 1)
      cout << k << endl;
    else if (n % 4 == 2)
      cout << t << endl;
    else if (n % 4 == 3)
      cout << p << endl;
    else if (n % 4 == 0)
      cout << s << endl;
  }
  return 0;
}
