#include "bits/stdc++.h" #define ALL(obj) (obj).begin(),(obj).end() #define RALL(obj) (obj).rbegin(),(obj).rend() #define REP(i, n) for(int i = 0; i < (int)(n); i++) #define REPR(i, n) for(int i = (int)(n); i >= 0; i--) #define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = MOD - 1; const ll LLINF = 4e18; //gcd template T gcd(T a, T b) { return b ? gcd(b, a%b) : a; } int main() { ll n, m; cin >> n >> m; ll g = gcd(n, m); n /= g; m /= g; int cnt2 = 0, cnt5 = 0; while (m % 2 == 0) { cnt2++; m /= 2; } while (m % 5 == 0) { cnt5++; m /= 5; } if (m > 1) { puts("-1"); } else { if (cnt2 > cnt5) { puts("5"); } else if (cnt5 > cnt2){ switch ((cnt5 - cnt2) % 4) { case 0: cout << n % 10 * 6 % 10 << endl; break; case 1: cout << n % 10 * 2 % 10 << endl; break; case 2: cout << n % 10 * 4 % 10 << endl; break; case 3: cout << n % 10 * 8 % 10 << endl; break; } } else { while (n % 10 == 0) { n /= 10; } cout << n % 10 << endl; } } getchar(); getchar(); }