#include using namespace std; typedef long long ll; typedef pair pii; #define pb push_back #define mp make_pair #define rep(i,n) for(int i=0;i<(n);++i) int main(){ cin.tie(0); ios::sync_with_stdio(false); int n;cin >> n; n%=6; n--; if(n<0) n+=6; vector a={2,8,5,7,2,4}; cout << a.at(n) << endl; }