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