742A : ARPA'S HARD EXAM AND MEHRDAD'S NAIVE CHEAT

//742A : ARPA'S HARD EXAM AND MEHRDAD'S NAIVE CHEAT

/*
 * Github Link of the Solution
 */


/*
 * Prerequisite:
 *     - Basic mathematics
 */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {   
   
    static class ProblemSolver{
        public void solveTheProblem(InputReader in,PrintWriter out){
           
            //Take the necessary inputs
            int n=in.nextInt();
           
            //Take care of the base cases
            if(n==0){
                out.print(1);
                return;
            }
                       
            //Display the result
            /*
             * Hint:
             *     - The number at the end repeats in certain intervals
             */
            int res=n%4;
            if(res==1)out.print(8);
            else if(res==2)out.print(4);
            else if(res==3)out.print(2);
            else out.print(6);
        }                   
    }
   
    //Default template for all the codes
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
   
    //Main method for all the codes
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemSolver problemSolver = new ProblemSolver();
        problemSolver.solveTheProblem(in, out);       
        out.close();       
    }

}