#include using namespace std; typedef long long ll; ll gcd(ll a,ll b) { ll tmp; while(a) { tmp = b; b = a; a = tmp % a; } return b; } ll n, m; int main() { // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); cin >> n >> m; ll t = gcd(n, m); n /= t; m /= t; if (m == 1) { while (n % 10 == 0) n /= 10; cout << n % 10; return 0; } ll _2 = 0, _5 = 0; while (m % 2 == 0) m /= 2, _2++; while (m % 5 == 0) m /= 5, _5++; if (m > 1) { cout << -1; return 0; } while (n % 10 == 0) n /= 10; n %= 10; while (_2--) { n *= 5; while (n % 10 == 0) n /= 10; n %= 10; } while (_5--) { n *= 2; while (n % 10 == 0) n /= 10; n %= 10; } cout << n; return 0; } /* __------__ /~ ~\ | //^\\//^\| /~~\ || o| |o|:~\ | |6 ||___|_|_||:| \__. / o \/' | ( O ) /~~~~\ `\ \ / | |~~\ | ) ~------~`\ /' | | | / ____ /~~~)\ (_/' | | | /' | ( | | | | \ / __)/ \ \ \ \ \/ /' \ `\ \ \|\ / | |\___| \ | \____/ | | /^~> \ _/ < | | \ \ | | \ \ \ -^-\ \ | ) `\_______/^\______/ */