#include "bits/stdc++.h" using namespace std; long long gcd(long long a, long long b){ if (b == 0) return a; return gcd(b, a%b); } int main() { long long N, M; cin >> N >> M; long long g = gcd(N, M); N /= g; M /= g; while (N % 10 == 0) N /= 10; N %= 10; while (M % 5 == 0){ M /= 5; N *= 2; N %= 10; } while (M % 2 == 0){ M /= 2; N *= 5; N %= 10; } if (M == 1) cout << N << endl; else cout << -1 << endl; }