import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String n = sc.next(); String m = sc.next(); int d = Integer.parseInt(String.valueOf(n.charAt(n.length() - 1))); int e = 0; if(m.length() > 1) { e = Integer.parseInt(String.valueOf(m.charAt(m.length() - 2)) + String.valueOf(m.charAt(n.length() - 1))); } else { e = Integer.parseInt(String.valueOf(m.charAt(0))); } int e1 = (e % 4); int ans = 1; for(int i = 0; i < e1; i++) { ans = (ans * d) % 10; } if(e == 0) ans = 1; if(d == 0) ans = 0; System.out.println(ans); } }