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; n = n % 10; for (;;) { while (m % 10 == 0) m /= 10; if (m == 1) { while (n % 10 == 0) n /= 10; return n % 10; } if (m % 2 == 0) { m *= 5; n = (n * 5) % 10; } else if (m % 5 == 0) { m *= 2; n = (n * 2) % 10; } else { return -1; } } }