#!/usr/bin/env python3 import sys input = sys.stdin.readline from fractions import gcd import numpy n = int(input()) m = int(input()) base = m // gcd(n, m) while base % 2 == 0: base //= 2 while base % 5 == 0: base //= 5 if base == 1: val = numpy.divide(n, m, dtype="float128") s = str(val) if "e" in s: index = s.find("e") - 1 else: index = len(s) - 1 while s[index] in ".0": index -= 1 print(s[index]) else: print(-1)