#include <bits/stdc++.h>
using namespace std;
double pi = 4 * atan(1.0);
double eps = 1e-9;
string stringmin = "!";
string stringmax = "~";
int main() {
  cout.precision(14);
  int n;
  cin >> n;
  if (n == 0) {
    cout << 1;
    return 0;
  }
  switch (n % 4) {
    case 0:
      cout << 6;
      break;
    case 1:
      cout << 8;
      break;
    case 2:
      cout << 4;
      break;
    case 3:
      cout << 2;
      break;
  }
  return 0;
}
