import std.algorithm, std.conv, std.range, std.stdio, std.string; import std.bigint; // BigInt void main() { auto n = readln.chomp.to!long; auto m = readln.chomp.to!long; writeln(calc(n, m)); } auto calc(long n, long m) { if (n % m == 0) return dsr(n / m); auto f1 = powers(m, 2); auto f2 = powers(m, 5); if (m != 2L ^^ f1 * 5L ^^ f2) return -1; auto k = n.to!BigInt; if (f1 < f2) k *= 2 ^^ (f2 - f1); if (f1 > f2) k *= 5 ^^ (f1 - f2); return dsr(k); } auto powers(long n, int d) { auto c = 0; for (; n % d == 0; n /= d) ++c; return c; } auto dsr(T)(T n) { while (n % 10 == 0) n /= 10; return (n % 10).to!int; }