#include using namespace std; #define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++) #define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++) #define all(n) (n).begin(),(n).end() typedef vector Vi; typedef vector VVi; typedef pair Pii; typedef vector VPii; int main(){ long long A,B; cin >> A >> B; long long G = __gcd(A,B); A /= G; B /= G; if( A % B == 0 ){ long long T = A / B; while( T % 10 == 0 ) T /= 10; cout << T % 10 << endl; return 0; }else{ A %= B; set used; __int128 P = A; __int128 Q = B; int ans = 0; for(int i = 0 ; P && i < 1000 ; i++){ if( i == 999 ){ cout << -1 << endl; return 0; } P = P * 10; ans = P / Q; P %= Q; } cout << ans << endl; } }