import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; T read(T)() { return readln.chomp.to!T; } T[] reads(T)() { return readln.split.to!(T[]); } alias readint = read!int; alias readints = reads!int; T gcd(T)(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } int calc(long n, long m) { long g = gcd(n, m); n /= g; m /= g; int d2 = 0; int d5 = 0; while (m % 2 == 0) { d2++; m /= 2; } while (m % 5 == 0) { d5++; m /= 5; } if (m != 1) return -1; while (d2 < d5) { d2++; n *= 2; } while (d5 < d2) { d5++; n *= 5; } while (n % 10 == 0) n /= 10; return n % 10; } void main() { long n = read!long; long m = read!long; auto ans = calc(n, m); writeln(ans); }