#include using namespace std; long long long_gcd(long long a, long long b) { if (a < b) { long long x = a; a = b; b = x; } long long r; for (;b > 0;){ r = a % b; a = b; b = r; } return a; } int last_dig(long long a) { if (a == 0) {return 0;} for (;a % 10 == 0;) { a /= 10; } return a % 10; } int main(void) { long long N, M; cin >> N >> M; long long daiyaku = long_gcd(N, M); long long nshou = N / daiyaku; long long mshou = M / daiyaku; if (mshou == 1) { cout << last_dig(nshou) << endl; return 0; } long long digit = nshou % mshou; for (;mshou % 2 == 0;) { digit *= 5; mshou /= 2; } digit = last_dig(digit); for (;mshou % 5 == 0;) { digit <<= 1; mshou /= 5; } if (mshou > 1) { cout << -1 << endl; } else { digit = last_dig(digit); cout << digit << endl; } return 0; }