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

/* 
Problem Name: Arpa’s hard exam and Mehrdad’s naive cheat
URL: http://codeforces.com/contest/742/problem/A
*/

import java.util.*;

public class Arpas_hard_exam_and_Mehrdads_naive_cheat{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int num = 8; //1378

		int n = sc.nextInt();
		String s2 = Integer.toString(n);
		int len = s2.length();
		StringBuilder sb;
		if(len>4){
			sb = new StringBuilder();
			sb.append(s2.charAt(0));
			sb.append(s2.charAt(1));
			sb.append(s2.charAt(3));
		}else{
			sb = new StringBuilder(s2);
		}
		String s3 = sb.toString();
		n = Integer.parseInt(s3);


		int t = num;

		for(int i = 2;i<=n;i++){
			t = t * num;
			
			String s1 = Integer.toString(t);
			int length = s1.length();
			char ch = s1.charAt(length-1);
			t = Character.getNumericValue(ch);

		}

		System.out.println(t); 
	}
}