import java.util.*; class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt()%6; int ans; if (n == 1) ans = 2; else if (n == 2) ans = 8; else if (n == 3) ans = 5; else if (n == 4) ans = 7; else if (n == 5) ans = 1; else ans = 4; System.out.println(ans); } }