#include #include #include #include #define REP(i, a, b) for (int i = int(a); i < int(b); i++) #define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl using namespace std; typedef long long int lli; template vector make_v(size_t a, T b) { return vector(a, b); } template auto make_v(size_t a, Ts... ts) { return vector(a, make_v(ts...)); } lli gcd(lli a, lli b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int main() { lli N, M; cin >> N >> M; lli g = gcd(N, M); N /= g; M /= g; if (M == 1) { while (N % 10 == 0) { N /= 10; } cout << N % 10 << endl; } else { int two = 0, five = 0; while (M % 2 == 0) { two++; M /= 2; } while (M % 5 == 0) { five++; M /= 5; } if (M != 1) { cout << -1 << endl; } else { if (two < five) { N %= 10; cout << ((1LL << (five - two)) * N) % 10 << endl; } else if (two > five) { cout << 5 << endl; } else { cout << N % 10 << endl; } } } return 0; }