#include using namespace std; typedef long long ll; int main() { int a[6] = {4,2,8,5,7,1}; int n; cin >> n; cout << a[n % 6] << '\n'; return 0; }