#include using namespace std; int main() { int N; cin >> N; N--; int n[6] = { 2, 8, 5, 7, 1,4 }; int ans = n[ N % 6]; cout << ans << endl; }