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.io.*;
import java.util.*;

import static java.lang.Math.*;

/**
 * Created by Dmitry on 04.12.2016.
 */

public class Main {

    public static void main(String[] args) throws Exception {
        new Main().solve();
    }

    MyScanner scanner;
    PrintWriter writer;

    int n;

    void solve() throws Exception {
        init();

        Map<Integer, Integer> ans = new HashMap<>();
        ans.put(0, 6);
        ans.put(1, 8);
        ans.put(2, 4);
        ans.put(3, 2);

        n = scanner.nextInt();

        writer.println(n == 0 ? 1 : ans.get(n % 4));

        save();
    }




    void init() throws Exception {
        scanner = new MyScanner("input.txt");
        writer = System.getProperty("ONLINE_JUDGE") != null
                ? new PrintWriter(System.out)
                : new PrintWriter("output.txt");


    }

    void save() {

        writer.flush();
        writer.close();
    }



    class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner(String fileName) throws FileNotFoundException {
            if (System.getProperty("ONLINE_JUDGE") != null)
                br = new BufferedReader(new InputStreamReader(System.in));
            else
                br = new BufferedReader(new FileReader(fileName));

        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }

}


