module main; import std; void main() { auto N = readln.chomp.to!ulong; auto M = readln.chomp.to!ulong; if (M == 1uL) { while (N % 10 == 0) N /= 10; writeln(N % 10); return; } while (M % 10 == 0) M /= 10; auto L = M; while (L % 2 == 0) L >>= 1; while (L % 5 == 0) L /= 5; if (L != 1uL) { writeln(-1); return; } BigInt A = N, B = M, Q, R; do { divMod(A, B, Q, R); A = R * 10; } while (R != 0); writeln(Q.toDecimalString().stripRight("0")[$-1]); }