import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random; import std.string, std.conv, std.stdio, std.typecons; void main() { auto n = readln.chomp.to!long; auto m = readln.chomp.to!long; reductFrac(n, m); if (n % m == 0) { writeln(lastWithoutZero(n / m)); } else { writeln(lastDecimal(n, m)); } } void reductFrac(ref long n, ref long m) { auto g = gcd(n, m); n /= g; m /= g; } int lastWithoutZero(long n) { while (n % 10 == 0) n /= 10; return n % 10; } int lastDecimal(long n, long m) { auto r = n % 10; for (; m % 5 == 0; m /= 5) r = (r % 5) * 2; for (; m % 2 == 0; m /= 2) r = (r % 2 == 0 ? r / 2 : 5); return (m > 1 ? -1 : r).to!int; }