#include using namespace std; __int128 gcd(__int128 a, __int128 b) { if (b == 0) { return a; } return gcd(b, a % b); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); unsigned long long int n, m; cin >> n >> m; __int128 N = n; __int128 M = m; __int128 g = gcd(N, M); N /= g; M /= g; __int128 temp = M; while (1) { if (temp % 2 != 0) { break; } temp /= 2; } while (1) { if (temp % 5 != 0) { break; } temp /= 5; } if (temp > 1) { cout << -1 << '\n'; return 0; } int res = 0; __int128 XX = N / M; while (XX > 0) { if (XX % 10 != 0) { res = XX % 10; break; } XX /= 10; } N %= M; while (1) { if (N == 0) { break; } N *= 10; __int128 a = N / M; N %= M; //cout << N << ' ' << a << '\n'; res = a; } cout << res << '\n'; return 0; }