#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define endl '\n' #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) typedef long long ll; typedef pair P; typedef unsigned int uint; typedef unsigned long long ull; struct pairhash { public: template size_t operator()(const pair &x) const { size_t seed = hash()(x.first); return hash()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2); } }; const int inf = 1000000009; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } P finite(ll k) { P p = P(0, 0); while (k % 2 == 0) { k /= 2; p.first++; } while (k % 5 == 0) { k /= 5; p.second++; } return (k == 1 ? p : P(-1, -1)); } int main() { ll n, m; scanf("%lld%lld", &n, &m); ll g = gcd(n, m); n /= g; m /= g; P p = finite(m); if (p.first < 0) { printf("-1\n"); } else { while (n % 10 == 0) n /= 10; int d = n % 10; if (p.second > 0) { int a[4] = {6, 2, 4, 8}; d *= a[p.second%4]; } if (p.first > 0) { d *= 5; } while (d % 10 == 0) d /= 10; printf("%d\n", d%10); } }