#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); unsigned long long N,M; cin >> N >> M; auto g = gcd(N,M); N /= g; M /= g; auto m = M; while(M%2 == 0) M /= 2; while(M%5 == 0) M /= 5; if(M != 1){cout << "-1\n"; return 0;} swap(m,M); while(N%10 == 0) N /= 10; while(M%10 == 0) M /= 10; if(M == 1) cout << N%10 << endl; else if(M%2 == 0){ while(N%2 == 0) N /= 2; cout << N%10*5%10 << endl; } else{ while(N%5 == 0) N /= 5; int log5 = 0; while(M%5 == 0) log5++,M /= 5; log5 %= 4; if(log5 == 0) cout << N%10*6%10 << endl; if(log5 == 1) cout << N%10*2%10 << endl; if(log5 == 2) cout << N%10*4%10 << endl; if(log5 == 3) cout << N%10*8%10 << endl; } }