#include using namespace std; using ll = long long; ll gcd(ll a, ll b) { if(a % b == 0) return b; return gcd(b, a % b); } int main(void) { ll N, M; cin >> N >> M; ll d = gcd(N, M); N /= d, M /= d; while(N % 10 == 0) N /= 10; while(M % 10 == 0) M /= 10; int ans = N % 10; ll T = M; while(T % 2 == 0) { T /= 2; ans = 5; } while(T % 5 == 0) { T /= 5; ans = ans * 2 % 10; } cout << (T == 1 ? ans : -1) << endl; return 0; }