#include <bits/stdc++.h>
using namespace std;
int main() {
  int Case = 1;
  int n, m, k;
  char dump[2];
  while (cin >> n) {
    int second[] = {6, 8, 4, 2};
    if (n > 0)
      cout << second[n % 4] << endl;
    else
      puts("1");
  }
  return 0;
}
