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.*;

public class Kross {
    public void solve() 
    {
        int n = nextInt();
        switch (n % 4)
        {
            case 1:
                System.out.print("8");
                break;
            case 2:
                System.out.print("4");
                break;
            case 3:
                System.out.print("2");
                break;
            case 0:
                System.out.print("6");
                break;
        }
    }
public static void main (String[]args){
        new Kross().run();
    }

    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    private void run () {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            //br = new BufferedReader(new FileReader("birthday.in"));
            //out = new PrintWriter(new FileWriter("birthday.out"));
            solve();
            br.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

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

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