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

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Arrays;
import java.util.HashSet; 

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef{
	
	static long digit(long n) {
				
		long temp =n;
		long cc=0;
		while(temp-->0) {
			n = n*10;
		}
		return n;
		
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		FastReader sc = new FastReader();
	    PrintWriter out = new PrintWriter(System.out, true);
		int t=1;
		while(t-->0){		
			long n = sc.nextLong();
			if(n==0)
				System.out.println(1);
			else if(n%8==1||n%8==5)
				System.out.println(8);
			else if(n%8==2||n%8==6)
				System.out.println(4);
			else if(n%8==3||n%8==7)
				System.out.println(2);
			else if(n%8==4||n%8==0)
				System.out.println(6);
			
			//System.out.println(999999997%8);
		}
	}
		static class FastReader {
	    BufferedReader in;
	    StringTokenizer st;
	    
	    public FastReader() {
	        in = new BufferedReader(new InputStreamReader(System.in));
	    }
	    
	    String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try {
	                st = new StringTokenizer(in.readLine());
	            }
	            catch (Exception IO) {
	                IO.printStackTrace();
	            }
	        }
	        
	        return st.nextToken();
	    }
	    
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    
	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    
	    Double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    
	    String nextLine() {
	        String str = "";
	        try {
	            str = in.readLine();
	        } catch(Exception IO) {
	            IO.printStackTrace();
	        }
	        
	        return str;
	    }
	    
	    long[] nextLongArray(int size) {
	        long[] arr = new long[size];
	        
	        for (int i = 0; i < size; i++) {
	            arr[i] = this.nextLong();
	        }
	        
	        return arr;
	    }
	    
	    int[] nextIntegerArray(int size) {
	        int[] arr = new int[size];
	        
	        for (int i = 0; i < size; i++) {
	            arr[i] = this.nextInt();
	        }
	        
	        return arr;
	    }
	    
	    double[] nextDoubleArray(int size) {
	        double[] arr = new double[size];
	        
	        for (int i = 0; i < size; i++) {
	            arr[i] = this.nextDouble();
	        }
	        
	        return arr;
	    }
	    
	    void printArray(Object[] arr) {
	        for (int i = 0; i < arr.length; i++) {
	            System.out.println(arr[i] + " ");
	        }
	        System.out.println();
	    }
	}
}