#include #include using namespace std; long long N, M; int main() { cin >> N >> M; long long gcd = __gcd(N, M); N /= gcd; M /= gcd; int cnt2 = 0, cnt5 = 0; while (M % 2 == 0) { cnt2++; M /= 2; } while (M % 5 == 0) { cnt5++; M /= 5; } while (N % 10 == 0) { N /= 10; } N %= 10; if (M > 1) { cout << -1 << endl; } else { for (int i = 0; i < cnt5 - cnt2; i++) { N *= 2; N %= 10; } for (int i = 0; i < cnt2 - cnt5; i++) { N *= 5; N %= 10; } cout << N << endl; } return 0; }