#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long int j = 0, n, k = 1, r = 0;
  int a[] = {8, 4, 2, 6, 8, 4, 2, 6, 8, 4, 2, 6,
             8, 4, 2, 6, 8, 4, 2, 6, 8, 4, 2, 6};
  cin >> n;
  if (n >= 8 && n % 4 == 0) {
    cout << 6 << endl;
    return 0;
  }
  if (n == 0) {
    cout << 1 << endl;
    return 0;
  }
  if (n > 0 && n < 8) {
    cout << a[n - 1] << endl;
    return 0;
  }
  if (n > 8) {
    while ((n + j) % 4 != 0) {
      ++j;
    }
  }
  cout << a[7 - j] << endl;
  return 0;
}
