#include #include #include #include #include #include #include #include using namespace std; typedef long long ll; ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, M; cin >> N >> M; ll g = gcd(N, M); N /= g, M /= g; if(M == 1) { while(N % 10 == 0) N /= 10; cout << N % 10 << endl; return 0; } int t = 0, f = 0; ll m = M; while(m % 2 == 0) { m /= 2; t++; } while(m % 5 == 0) { m /= 5; f++; } if(m != 1) { cout << -1 << endl; return 0; } if(t > f) { for(int i = 0; i < t - f; i++) { N *= 5; N %= 1000000; while(N % 10 == 0) N /= 10; } } else { for(int i = 0; i < f - t; i++) { N *= 2; N %= 1000000; while(N % 10 == 0) N /= 10; } } cout << N % 10 << endl; }