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 java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) {

        FastScanner scr = new FastScanner();
//        int t = scr.nextInt();
//        while (t-- > 0)
        solve(scr);
    }

    static void solve(FastScanner in) {

        int n = in.nextInt();
        int i = n % 4;

        switch (i) {
            case 0:
            case 4:
                n = 6;
                break;
            case 3:
                n = 2;
                break;
            case 2:
                n = 4;
                break;
            default:
                n = 8;
        }
        System.out.println(n);
    }


    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokinizer;


        public FastScanner() {
            initilize(System.in);
        }


        public FastScanner(String path) {
            try {
                initilize(new FileInputStream(new File(path)));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        private void initilize(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        private String getToken() {
            while (tokinizer == null || !tokinizer.hasMoreTokens()) {
                try {
                    String str = reader.readLine();
                    if (str != null) tokinizer = new StringTokenizer(str);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokinizer.nextToken();
        }


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

        public long nextLong() {
            return Long.parseLong(getToken());
        }

        public double nextDouble() {
            return Double.parseDouble(getToken());
        }

        public String next() {
            return getToken();
        }

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


}
