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