#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  while (cin >> n) {
    int s = n % 4;
    if (n == 0)
      cout << "1\n";
    else
      switch (s) {
        case 0:
          cout << "6\n";
          break;
        case 1:
          cout << "8\n";
          break;
        case 2:
          cout << "4\n";
          break;
        case 3:
          cout << "2\n";
          break;
      }
  }
  return 0;
}
