#include using namespace std; typedef long long LL; int main(){ LL N, M; cin >> N >> M; LL n2 = 0; LL n5 = 0; while(N % 2 == 0){ N /= 2; n2++; } while(N % 5 == 0){ N /= 5; n5++; } while(M % 2 == 0){ M /= 2; n5++; } while(M % 5 == 0){ M /= 5; n2++; } if(N % M == 0){ LL ans = N / M % 10; for(int i = 0; i < n2-n5; i++){ ans = ans * 2 % 10; } for(int i = 0; i < n5-n2; i++){ ans = ans * 5 % 10; } cout << ans << endl; }else{ cout << -1 << endl; } return 0; }