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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;



public class Problem1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		int n = in.nextInt();
		if(n == 0)
		{
			out.println(1);
			out.close();
			return;
		}
		int rem = n % 4;
		if(rem == 1)
		{
			out.println(8);
		}
		else if(rem == 2)
		{
			out.println(4);
		}
		else if(rem == 3)
		{
			out.println(2);
		}
		else
		{
			out.println(6);
		}

		out.close();
	}
	
	static boolean possible(int m, StringBuilder min1, StringBuilder max1)
	{
		StringBuilder max = new StringBuilder();
		StringBuilder min = new StringBuilder();
		for(int i = 0; i < m; ++i)
		{
			max.append(9);
		}
		for(int i = 0; i < m; ++i)
		{
			if(i == 0)
			{
				min.append(1);
			}
			else
			{
				min.append(0);
			}
			
		}
		BigInteger a1 = new BigInteger(min1.toString());
		BigInteger a = new BigInteger(min.toString());
		BigInteger b1 = new BigInteger(max1.toString());
		BigInteger b = new BigInteger(max.toString());
		
		return a.compareTo(a1)  <= 0 && b1.compareTo(b)  <= 0;
	}

	static boolean can(int m, int s)
	{
		return s >= 0 && s  <= m*9;
	}
	
	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());
	    }
	    
	    public long nextLong()
	    {
	    	return Long.parseLong(next());
	    }

	}


}
