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