import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); String N = sc.next(); String M = sc.next(); int[][] answers = { {0}, {1}, {2, 4, 8, 6}, {3, 9, 7, 1}, {4, 6}, {5}, {6}, {7, 9, 3, 1}, {8, 4, 2, 1}, {9, 1}, }; final int N_mod_10 = Integer.parseInt(N.substring(N.length() - 1)); final int M_mod_100 = Integer.parseInt(M.substring(Math.max(0, M.length() - 2))); //System.out.println(N_mod_10 + ":" + M_mod_100); System.out.println(answers[N_mod_10]["0".equals(M) ? 0 : (100 + M_mod_100 - 1) % answers[N_mod_10].length]); } }