#include <bits/stdc++.h>
int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0) {
      printf("1\n");
      continue;
    }
    int a[5] = {0, 8, 4, 2, 6};
    if (n % 4 == 0)
      printf("%d\n", a[4]);
    else
      printf("%d\n", a[n % 4]);
  }
}
