#include #include #include using namespace std; #define LL long long int main(void){ LL N, M; cin >> N >> M; if (N%M == 0){ string str = to_string(N / M); for (int i = (int)str.size() - 1; i >= 0; i--){ if (str[i] != '0'){ cout << str[i]; break; } } } else{ int nx, ny; nx = ny = 0; while (N % 2 == 0)N /= 2, nx++; while (N % 5 == 0)N /= 5, ny++; while (M % 2 == 0)M /= 2, nx--; while (M % 5 == 0)M /= 5, ny--; // cout << nx << " " << ny << endl; if (N%M){ cout << -1 << endl; return 0; } while (nx < 0 || ny < 0)nx++, ny++; LL res = N / M; res %= 10; LL tmp = 1; while (nx--){ tmp = (tmp * 2) % 10; } if (ny>0)tmp *= 5; res = (res*tmp) % 10; cout << res << endl; } return 0; }