#!/usr/bin/env python3 import sys input = sys.stdin.readline from fractions import gcd n = int(input()) m = int(input()) g = gcd(n, m) n = n // g m = m // g twos = 0; fives = 0 while m % 2 == 0: m //= 2 twos += 1 while m % 5 == 0: m //= 5 fives += 1 if m == 1: if twos > fives: n *= pow(5, twos - fives) else: n *= pow(2, fives - twos) while n % 10 == 0: n //= 10 print(n % 10) else: print(-1)