import java.util.Scanner; public class Yuki025 { public static void main(String[] args) { Yuki025 p = new Yuki025(); } Yuki025() { Scanner scanner = new Scanner(System.in); long numerator = scanner.nextLong(); long denominator = scanner.nextLong(); System.out.println(solve(numerator, denominator)); } long gcd(long a, long b) { while (b > 0) { long c = a % b; a = b; b = c; } return a; } long pow(int v, int p, long init) { long ans = init % 10; for (int i = 0; i < p; i++) { ans *= v; ans %= 10; } return ans; } int getLastNonZero(long v) { long ans = v; while (ans % 10 == 0) { ans /= 10; } return (int) ans % 10; } int solve(long _numerator, long _denominator) { final long gcd = gcd(_numerator, _denominator); long numerator = _numerator / gcd; long denominator = _denominator / gcd; long num = denominator; if (num == 1) { return getLastNonZero(numerator); } int[] div = new int[6]; int[] divs = {2, 5}; for (int d : divs) { while (num > 1) { if (num % d > 0) { break; } div[d]++; num /= d; } } if (num > 1) { return -1; } final int diff = Math.max(div[5], div[2]) - Math.min(div[5], div[2]); if (div[5] == div[2]) { return (int) (numerator % 10); } else if (div[5] < div[2]) { return (int) pow(5, diff, numerator); } else { return (int) pow(2, diff, numerator); } } }