#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using vb = vector; using vvb = vector; using vd = vector; using vs = vector; using pii = pair; using pll = pair; using pdd = pair; using vpii = vector; using vpll = vector; using vpdd = vector; const int inf = (1 << 30) - 1; const ll INF = 1LL << 60; //const int MOD = 1000000007; const int MOD = 998244353; int main() { ll n, m; cin >> n >> m; bool b2 = false, b5 = false; int cnt2 = 0, cnt5 = 0; while (m % 2 == 0) { m /= 2; cnt2++; } while (m % 5 == 0) { m /= 5; cnt5++; } if (m > 1) { cout << -1 << endl; return 0; } if (cnt2 && cnt5) { while (n % 10 == 0) { n /= 10; } cout << n % 10 << endl; } else if (cnt2) { while (n % 2 == 0) { n /= 2; cnt2--; if (cnt2 == 0) break; } if (cnt2 == 0) { while (n % 10 == 0) { n /= 10; } cout << n % 10 << endl; } else { cout << 5 << endl; } } else { while (n % 5 == 0) { n /= 5; cnt5--; if (cnt5 == 0) break; } if (cnt5 == 0) { while (n % 10 == 0) { n /= 10; } cout << n % 10 << endl; } else { while (n % 10 == 0) { n /= 10; } int y = 2; for (int i = 1; i < cnt5; i++) { y *= 2; y %= 10; } unsigned long long x = n * y; while (x % 10 == 0) { x /= 10; } cout << x % 10 << endl; } } return 0; }