#include <bits/stdc++.h>
using namespace std;
bool qo(bool x) { return (x ? 0 : qo(!x)); }
const int mnx = 1e3 + 9;
const int mod = 1e9 + 7;
const double pi = acos(-1);
long long n;
long long a[5];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL);
  cin >> n;
  if (n == 0) {
    cout << 1;
    exit(0);
    ;
  }
  a[1] = 8;
  a[2] = 4;
  a[3] = 2;
  a[4] = 6;
  cout << a[(n % 4) + (n % 4 == 0) * 4] << '\n';
  return 0;
}
