#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  if (n == 0) {
    printf("1");
    return 0;
  }
  switch (n % 4) {
    case 0:
      printf("6");
      break;
    case 1:
      printf("8");
      break;
    case 2:
      printf("4");
      break;
    case 3:
      printf("2");
      break;
  }
}
