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 codeforces_742a;

import java.util.Scanner;

public class CodeForces_742A {

    public static void main(String[] args) {
        Menu menu = new Menu();
        Algorithm use = new Algorithm();
        int num;
//        menu.printOnDisplay("Welcome to my program!!!");
//        menu.printOnDisplay("\n");
//        menu.printOnDisplay("You have to input an integer and I will do every thing!!");
//        menu.printOnDisplay("\n");
        num = menu.getNumber();
//        menu.printOnDisplay("The last digit is: ");
        System.out.println(use.findLastNumber(String.valueOf(use.cal(num))));
    }

}

class Menu {

    public void printOnDisplay(String s) {
        System.out.print(s);
    }

    public int getNumber() {
        Scanner sc = new Scanner(System.in);
        int num = 0;
        boolean flag;
        do {
            try {
//                System.out.print("Input a number: ");
                num = Integer.parseInt(sc.nextLine());
                flag = true;
            } catch (Exception e) {
//                System.out.println("invalid value, please input again!!!");
                flag = false;
            }
        } while (num < 0 || flag == false);
        return num;
    }
}

class Algorithm {

    public double cal(int num) {
        int x = 1378;
        double result;
        result = Math.pow(x, num);
        return result;
    }

    public String findLastNumber(String s) {
        return s.substring((s.length() - 3), (s.length() - 2));
    }
}
