12
 1378
 51202278
 989898989
 4
 7
 9
 6
 8
 12193721
 999999995
 999999999
 11
 999999996
 999999998
 3
 14
 15
 10
 999999994
 1000
 13781378
 5
 999999997
 1000000000
 13
 16
 0

6
 4
 4
 8
 6
 2
 8
 4
 6
 8
 2
 2
 2
 6
 4
 2
 4
 2
 4
 4
 6
 4
 8
 8
 6
 8
 6
 1

import java.util.*;

// http://codeforces.com/contest/742/problem/A
public class HardExamNaiveCheat {
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		long n = rl();
		long rem = n%4;
		if(rem == 1)
			print(8);
		else if(rem==2)
			print(4);
		else if(rem==3)
			print(2);
		else
			print(6);
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	public static int ri() {
		return Integer.parseInt(sc.nextLine());
	}

	public static long rl() {
		return Long.parseLong(sc.nextLine());
	}

	public static double rd() {
		return Double.parseDouble(sc.nextLine());
	}

	public static String[] rsa() {
		return sc.nextLine().split(" ");
	}

	public static int[] ria() {
		String[] s = rsa();
		int[] arr = new int[s.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Integer.parseInt(s[i]);
		return arr;
	}

	public static long[] rla() {
		String[] s = rsa();
		long[] arr = new long[s.length];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Long.parseLong(s[i]);
		return arr;
	}

	public static int[] riaml(int m) {
		int[] arr = new int[m];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Integer.parseInt(sc.nextLine());
		return arr;
	}

	public static long[] rlaml(int m) {
		long[] arr = new long[m];
		for (int i = 0; i < arr.length; i++)
			arr[i] = Long.parseLong(sc.nextLine());
		return arr;
	}
}
