import java.math.BigInteger;

public class Solution {
    public static String solution(String x, String y) {
        BigInteger m = new BigInteger(x), f = new BigInteger(y);

        boolean found = false;
        BigInteger count = BigInteger.ZERO;
        while (!found && (m.signum() == 1 && f.signum() == 1)) { //loop when not found and values are not negative
            int comp = m.compareTo(f);
            if (comp > 0) {
                BigInteger[] vals = f.equals(BigInteger.ONE) ? //dividing one is the only case where it will not be equivalent to multiple subtraction, thus we must make an exception
                    new BigInteger[] { BigInteger.ONE, m.subtract(f) } : m.divideAndRemainder(f);
                count = count.add(vals[0]);
                m = vals[1];
            } else if (comp < 0) {
                BigInteger[] vals = m.equals(BigInteger.ONE) ? //as above
                    new BigInteger[] { BigInteger.ONE, f.subtract(m) } : f.divideAndRemainder(m);
                count = count.add(vals[0]);
                f = vals[1];
            } else {
                if (m.equals(BigInteger.ONE)) {  //no need to check f since they are equal
                    found = true;
                } else {
                    throw new IllegalStateException();  //it should never be possible for two non-1 values to be equal under the bomb replication constraints
                }
            }
        }

        return found ? count.toString() : "impossible";

    }
}