#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b;
  cin >> a;
  b = a % 4;
  if (a == 0)
    cout << 1;
  else {
    if (b == 1) cout << 8;
    if (b == 2) cout << 4;
    if (b == 3) cout << 2;
    if (b == 0) cout << 6;
  }
  return 0;
}
