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(0))); int e = 0; if(m.length() > 1) { e = Integer.parseInt(String.valueOf(m.charAt(1)) + String.valueOf(m.charAt(0))); } else { e = Integer.parseInt(String.valueOf(m.charAt(0))); } e = (e % 4); int ans = 1; for(int i = 0; i < e; i++) { ans *= d; } System.out.println(ans); } }