12
 1378
 51202278
 989898989
 4
 7
 9
 6
 8
 12193721
 999999995
 999999999
 11
 999999996
 999999998
 3
 14
 15
 10
 999999994
 1000
 13781378
 5
 999999997
 1000000000
 13
 16
 0

6
 4
 4
 8
 6
 2
 8
 4
 6
 8
 2
 2
 2
 6
 4
 2
 4
 2
 4
 4
 6
 4
 8
 8
 6
 8
 6
 1

#include <bits/stdc++.h>
using namespace std;
long long pow(long long a, long long b, long long p) {
  long long sum = 1;
  for (a %= p; b; a = a * a % p, b >>= 1)
    if (b & 1) sum = sum * a % p;
  return sum;
}
long long phi(long long n) {
  long long i, re = n;
  for (i = 2; i * i <= n; i++)
    if (n % i == 0) {
      re = re / i * (i - 1);
      while (n % i == 0) n /= i;
    }
  if (n > 1) re = re / n * (n - 1);
  return re % 1000000007;
}
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  exgcd(b, a % b, y, x);
  y -= x * (a / b);
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int gg[10], n;
  gg[1] = 8;
  gg[2] = 4;
  gg[3] = 2;
  gg[0] = 6;
  scanf("%d", &n);
  if (n == 0)
    printf("1\n");
  else {
    printf("%d\n", gg[n % 4]);
  }
}
