#include using namespace std; int main(){ int N; cin >> N; if(N % 6 == 1){ cout << 2 << endl; }else if(N % 6 == 2){ cout << 8 << endl; }else if(N % 6 == 3){ cout << 5 << endl; }else if(N % 6 == 4){ cout << 7 << endl; }else if(N % 6 == 5){ cout << 1 << endl; }else{ cout << 4 << endl; } }