Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox, how are you going to do that?", the curious bears asked. "It's easy", said the fox. "If the mass of a certain piece is divisible by two, then I can eat exactly a half of the piece. If the mass of a certain piece is divisible by three, then I can eat exactly two-thirds, and if the mass is divisible by five, then I can eat four-fifths. I'll eat a little here and there and make the pieces equal". The little bears realize that the fox's proposal contains a catch. But at the same time they realize that they can not make the two pieces equal themselves. So they agreed to her proposal, but on one condition: the fox should make the pieces equal as quickly as possible. Find the minimum number of operations the fox needs to make pieces equal.

The first line contains two space-separated integers a and b (1 ≤ a, b ≤ 109).

If the fox is lying to the little bears and it is impossible to make the pieces equal, print -1. Otherwise, print the required minimum number of operations. If the pieces of the cheese are initially equal, the required number is 0.

import java.io.*;
import java.util.*;

public class CF {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

        StringTokenizer st = new StringTokenizer(br.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());

        int[] factors1 = new int[6];
        int[] factors2 = new int[6];

        int[] nums = {2, 3, 5};
        for (int num : nums) {
            while (a % num == 0) {
                a /= num;
                factors1[num]++;
            }

            while (b % num == 0) {
                b /= num;
                factors2[num]++;
            }
        }

        if (a != b) {
            pw.println(-1);
        } else {
            int ret = 0;

            for (int num : nums) {
                ret += Math.abs(factors1[num] - factors2[num]);
            }

            pw.println(ret);
        }

        pw.close();
    }
}

import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader fr = new FastReader();
        int a = fr.nextInt();
        int b = fr.nextInt();

        int moves = 0;
        int gcd = gcd(a, b);
        a /= gcd;
        b /= gcd;

        while(a % 5 == 0) {
            moves++;
            a /= 5;
        }
        while(a % 3 == 0) {
            moves ++;
            a /= 3;
        }
        while (a % 2 == 0) {
            moves++;
            a /= 2;
        }
        while(b % 5 == 0) {
            moves++;
            b /= 5;
        }
        while(b % 3 == 0) {
            moves++;
            b /= 3;
        }
        while (b % 2 == 0) {
            moves++;
            b /= 2;
        }
        if(a == b)
            System.out.println(moves);
        else
            System.out.println(-1);
    }

    private static int gcd(int a, int b) {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
}

class FastReader {
    private BufferedReader br;
    private StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

import java.util.*;
    import java.io.*;

    public class Codeforces {

        public static void main(String[] args) throws IOException {
            Reader.init(System.in);
            int a = Reader.nextInt();
            int b = Reader.nextInt();
            int count = 0;

            int x = getPow(a, 2);
            int y = getPow(b, 2);
            count += Math.abs(x-y);
            a /= Math.pow(2, x);
            b /= Math.pow(2, y);

            x = getPow(a, 3);
            y = getPow(b, 3);
            count += Math.abs(x-y);
            a /= Math.pow(3, x);
            b /= Math.pow(3, y);

            x = getPow(a, 5);
            y = getPow(b, 5);
            count += Math.abs(x-y);
            a /= Math.pow(5, x);
            b /= Math.pow(5, y);

            if(a == b)
                System.out.println(count);
            else
                System.out.println(-1);

        }

        public static int getPow(int n, int x){
            int p = 0;

            while(n % x == 0){
                p++;
                n /= x;
            }

            return p;
        }
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

    @Override
    public int compareTo(Pair t) {
        int x = this.a - t.a;

        if(x == 0)
            return this.b - t.b;

        return x;
    }

    }

    class Reader {

        static BufferedReader reader;
        static StringTokenizer tokenizer;

        /**
         * call this method to initialize reader for InputStream
         */
        static void init(InputStream input) {
            reader = new BufferedReader(
                    new InputStreamReader(input));
            tokenizer = new StringTokenizer("");
        }

        /**
         * get next word
         */
        static String next() throws IOException {
            while (!tokenizer.hasMoreTokens()) {
                //TODO add check for eof if necessary
                tokenizer = new StringTokenizer(
                        reader.readLine());
            }
            return tokenizer.nextToken();
        }

        static int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        static byte nextByte() throws IOException {

            return Byte.parseByte(next());
        }

        static long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        static double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    }

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class FoxDividingCheese {
    static long gcd(long a ,long b){
        return b==0?a:gcd(b, a%b);
    }
    static long lcm(long a,long b){
        return (a*b)/gcd(a, b);
    }
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(in.readLine());
        long a = Integer.parseInt(st.nextToken());
        long b = Integer.parseInt(st.nextToken());
        int op = 0;
        long gc = gcd(a, b);
        a/=gc;
        b/=gc;
        int arr[] = {2,3,5};

        for(int i = arr.length-1;i>=0;i--){
            while(a%arr[i]==0){
                op++;
                a/=arr[i];
            }
        }
        for(int i = arr.length-1;i>=0;i--){
            while(b%arr[i]==0){
                op++;
                b/=arr[i];
            }
        }
        if(a!=1||b!=1){
            out.println(-1);
        }
        else{
            out.println(op);
        }
        in.close();
        out.close();
    }

}

//package solve;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Solve {

    private static Map<Integer, Integer> fillMapAdd(int value){
        Map<Integer, Integer> map = new HashMap<>();

        return map;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int array[] = new int[3];
        int a = sc.nextInt();
        boolean bool = true;
        while(bool){
            bool = false;
            if(a % 2 == 0){
                array[0]++;
                a /= 2;
                bool = true;
            }
            if(a % 3 == 0){
                array[1]++;
                a /= 3;
                bool = true;
            }
            if(a % 5 == 0){
                array[2]++;
                a /= 5;
                bool = true;
            }
        }
        int b = sc.nextInt();
        bool = true;
        while(bool){
            bool = false;
            if(b % 2 == 0){
                array[0]--;
                b /= 2;
                bool = true;
            }
            if(b % 3 == 0){
                array[1]--;
                b /= 3;
                bool = true;
            }
            if(b % 5 == 0){
                array[2]--;
                b /= 5;
                bool = true;
            }
        }
        if(a != b){
            System.out.println("-1");
        }else{
            System.out.println(Math.abs(array[0]) + Math.abs(array[1]) + Math.abs(array[2]));
        }
        sc.close();
    }

}

import java.lang.*;
import java.io.*;
import java.util.*;

public class code
{
    public static void main(String args[])
    {
     	Scanner scn = new Scanner(System.in);
    	MutableInt a = new MutableInt(scn.nextInt());
    	MutableInt b = new MutableInt(scn.nextInt());

    	int a_2 = findNumber(a, 2);
    	int a_3 = findNumber(a, 3);
    	int a_5 = findNumber(a, 5);

    	int b_2 = findNumber(b, 2);
    	int b_3 = findNumber(b, 3);
    	int b_5 = findNumber(b, 5);

    	if(b.data !=a.data)
    	{
    		System.out.println(-1);
    		return;
    	}
    	int result = 0;
    	result = Math.abs(a_5 - b_5) + Math.abs(a_3 - b_3) + Math.abs(a_2 - b_2);

     	System.out.println(result);
    }

    public static int findNumber(MutableInt x, int p)
    {
    	int count = 0;
    	while(x.data%p==0)
    	{
    		count++;
    		x.data = x.data/p;
    	}
    	return count;
    }
}

class MutableInt
{
	int data;
	public MutableInt(int data)
	{
		this.data = data;
	}
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.ObjectInputStream.GetField;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);

		String[] cpt = s.nextLine().split(" ");
		int a = Integer.parseInt(cpt[0]);
		int b = Integer.parseInt(cpt[1]);

		int[] aDiv = dividers(a);
		int[] bDiv = dividers(b);

		if (aDiv[3] != bDiv[3]) {
			System.out.println(-1);
		} else {
			int ans = 0;
			for (int i = 0; i < 3; i++) {
				ans += Math.abs(aDiv[i] - bDiv[i]);
			}
			System.out.println(ans);
		}
	}

	public static int[] dividers(int i) {
		int[] result = new int[4];

		while (true) {
			if (i % 2 == 0) {
				i /= 2;
				result[0]++;
			} else if (i % 3 == 0) {
				i /= 3;
				result[1]++;
			} else if (i % 5 == 0) {
				i /= 5;
				result[2]++;
			} else {
				break;
			}
		}

		result[3] = i;

		return result;
	}
}

import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int AA = sc.nextInt();
		int BB = sc.nextInt();
		int[][] fac = new int[2][3];

		while(AA%2==0){fac[0][0]++;AA/=2;}
		while(AA%3==0){fac[0][1]++;AA/=3;}
		while(AA%5==0){fac[0][2]++;AA/=5;}
		while(BB%2==0){fac[1][0]++;BB/=2;}
		while(BB%3==0){fac[1][1]++;BB/=3;}
		while(BB%5==0){fac[1][2]++;BB/=5;}

		int ans = 0;
		for(int a=0;a<3;a++)
			ans+=Math.abs(fac[0][a]-fac[1][a]);

		if(AA!=BB)
			ans=-1;

		System.out.println(ans);
	}
}

//package com.example.programmingpractice;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class CodeforcesNT {

    static String[] sTakeInputs;
    static int sIntInputPos = 0;
    static int sLongInputPos = 0;
    static BufferedReader sBufferedReader;

    static int[] scanIntArray() throws Exception{
        String[] inputs = sBufferedReader.readLine().trim().split(" ");
        int[] arr = new int[inputs.length];
        for(int i = 0; i<inputs.length; i++) arr[i] = Integer.parseInt(inputs[i]);
        return arr;
    }

    static long[] scanLongArray() throws Exception{
        String[] inputs = sBufferedReader.readLine().trim().split(" ");
        long[] arr = new long[inputs.length];
        for(int i = 0; i<inputs.length; i++) arr[i] = Long.parseLong(inputs[i]);
        return arr;
    }

    static int scanInt() throws Exception{
        return Integer.parseInt(sBufferedReader.readLine().trim());
    }

    static long scanLong() throws Exception{
        return Long.parseLong(sBufferedReader.readLine().trim());
    }

    static int nextInt() throws Exception {
        if(sIntInputPos == 0) sTakeInputs = sBufferedReader.readLine().trim().split(" ");
        if(sTakeInputs.length <= sIntInputPos) {
            System.out.println("Warning input limit exceeded!!!"); return 0;
        }
        return Integer.parseInt(sTakeInputs[sIntInputPos++]);
    }

    static long nextLong() throws Exception {
        if(sLongInputPos == 0) sTakeInputs = sBufferedReader.readLine().trim().split(" ");
        if(sTakeInputs.length <= sLongInputPos) {
            System.out.println("Warning input limit exceeded!!!"); return 0;
        }
        return Long.parseLong(sTakeInputs[sLongInputPos++]);
    }

    static int gcd(int a, int b) {
        if(a%b == 0) return b;
        return gcd(b, a%b);
    }

    static ArrayList<Integer> getPrimes(boolean[] checker) {
        checker[0] = checker[1] = true;
        for(int i = 2; i*i<=checker.length; i++) {
            for(int j = 2; i*j<checker.length; j++) checker[i*j] = true;
        }
        ArrayList<Integer> primes = new ArrayList<>();
        for(int i = 2; i<checker.length; i++) {
            if(!checker[i]) primes.add(i);
        }
        return primes;
    }

    static int[] factorization(int x) {
        int[] factors = new int[7];
        while(x%2 == 0) {
            factors[2]++;
            x/=2;
        }
        while(x%3 == 0) {
            factors[3]++;
            x/=3;
        }
        while(x%5 == 0) {
            factors[5]++;
            x/=5;
        }
        factors[6] = x;
        return factors;
    }

    public static void main (String[] args) throws Exception {
        sBufferedReader = new BufferedReader(new InputStreamReader(System.in));

        int n = nextInt();
        int m = nextInt();
        if(n == m) {
            System.out.println("0"); return;
        }
        int[] nrr = factorization(n);
        int[] mrr = factorization(m);

        if(nrr[6] != mrr[6]) {
            System.out.println("-1"); return;
        }
        int steps = Math.abs(nrr[2]-mrr[2]) + Math.abs(nrr[3]-mrr[3]) + Math.abs(nrr[5]-mrr[5]);
        System.out.println(steps);
    }
}

// package CF;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
	public static void main(String[] args) throws Exception {
		Scanner bf = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
		int[] a = { bf.nextInt(), bf.nextInt() };
		int[] b = { 2, 3, 5 };
		int[][] pow = new int[2][3];
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < b.length; j++) {
				while (a[i] % b[j] == 0) {
					pow[i][j]++;
					a[i] /= b[j];
				}
			}
		}
		if (a[0] != a[1])
			out.println(-1);
		else {
			int ans = 0;
			for (int i = 0; i < pow[0].length; i++)
				ans += Math.abs(pow[0][i] - pow[1][i]);
			out.println(ans);
		}
		out.print(sb);
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

import java.util.*;
import java.io.*;;

public class E {

	static ArrayList<Integer> primes; // generated by sieve

	/*
	 * 1. Generating a list of prime factors of N
	 */
	static int[] primeFactors(int N) // O(sqrt(N) / ln sqrt(N))
	{
		int[] factors = new int[100000];// take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while (p * 1l * p <= N) {
			int c = 0;
			while (N % p == 0) {
				N /= p;
				c++;
			}
			factors[p] += c;
			p = primes.get(++idx);
		}

		if (N != 1) { // last prime factor may be > sqrt(N)
			if (N > 100000)
				factors[factors.length - 1] = N;
			else
				factors[N]++;
		} // for integers whose largest prime factor has a power of 1
		return factors;
	}

	static int[] isComposite;

	static void sieve(int N) // O(N log log N)
	{
		isComposite = new int[N + 1];
		isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i) // can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
			if (isComposite[i] == 0) // can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if (1l * i * i <= N)
					for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in
														// modified sieve
						isComposite[j] = 1;
			}
	}

	static ArrayList<Integer>[] adjList;
	static int V, counter, SCC, dfs_num[], dfs_low[];
	static boolean[] inSCC;
	static Stack<Integer> stack;
	static int[] cost;
	static long ans;
	static long r;

	static void tarjanSCC() // O(V + E)
	{
		for (int i = 0; i < V; ++i)
			if (dfs_num[i] == 0)
				tarjanSCC(i);
	}

	static void tarjanSCC(int u) {
		dfs_num[u] = dfs_low[u] = ++counter;
		stack.push(u);

		for (int v : adjList[u]) {
			if (dfs_num[v] == 0)
				tarjanSCC(v);
			if (!inSCC[v])
				dfs_low[u] = Math.min(dfs_low[u], dfs_low[v]);
		}
		if (dfs_num[u] == dfs_low[u]) {
			// SCC found
			SCC++;
			int c = 0;
			int min = 1000000000;

			while (true) {
				int v = stack.pop();
				if (min > cost[v]) {
					c = 1;
					min = cost[v];
				} else if (min == cost[v])
					c++;
				inSCC[v] = true;
				if (v == u)
					break;
			}
			r = r + min;
			ans = (ans * 1l * c) % 1000000007;
		}
	}

	static ArrayList<Integer> arr;
	static int n;
	static int m;
	static int k1;
	static int k2;
	static long[][][][] memo;

	static long dp(int idx, int t, int c, int l) {
		if (idx == n + m) {
			return 1;
		}
		if (t == n) {
			if (n + m - idx > k2)
				return 0;
			else
				return 1;
		}
		if (idx - t == m) {
			if (n - t > k1)
				return 0;
			else
				return 1;
		}
		if (memo[idx][t][c][l] != -1)
			return memo[idx][t][c][l];
		long max = 0;
		if (l == 0) {
			if (c == k1)
				max += dp(idx + 1, t, 1, 1);
			else {
				max += (dp(idx + 1, t + 1, c + 1, l) + dp(idx + 1, t, 1, 1)) % 100000000;
			}
		} else {
			if (c == k2)
				max += dp(idx + 1, t + 1, 1, 0);
			else {
				max += (dp(idx + 1, t, c + 1, l) + dp(idx + 1, t + 1, 1, 0)) % 100000000;
			}
		}
		return memo[idx][t][c][l] = max;
	}

	static long[] cum;

	public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());

		sieve(100000);
		int[] a = primeFactors(n);
		int[] b = primeFactors(m);
//		System.out.println(b[b.length - 1]);
		int d = Math.max(a[2], b[2]) - Math.min(a[2], b[2]) + Math.max(a[3], b[3]) - Math.min(a[3], b[3])
				+ Math.max(a[5], b[5]) - Math.min(a[5], b[5]);
		boolean f = true;
		for (int i = 7; i < 100000 && f; i++)
			if (a[i] != b[i])
				f = false;
		if (f)
			pw.println(d);
		else
			pw.println(-1);
		pw.flush();
		pw.close();

	}

	static long dis(int x, int y, int z, int w) {
		return (x - z) * (x - z) + (y - w) * (y - w);
	}

	static int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int d, int u) {
			x = d;
			y = u;
		}

		@Override
		public int compareTo(pair o) {
			// TODO Auto-generated method stub
			if (x == o.x)
				return y - o.y;
			return x - o.x;
		}

	}

	static class triple implements Comparable<triple> {
		int x;
		int y;
		int z;

		public triple(int a, int b, int c) {
			x = a;
			y = b;
			z = c;
		}

		@Override
		public int compareTo(triple o) {
			// TODO Auto-generated method stub
			return y - o.y;
		}
	}
}

//Program by Matthew Savage
//With help from the TJHSST SCT Grader Example Class

import java.io.*;
import java.util.*;

public class B{
   public static boolean DEBUG = false;

	public static void main(String[] args) throws IOException{
      //BufferedReader br = new BufferedReader(new FileReader("B.in")); //for testing
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //for real
		PrintWriter pw = new PrintWriter(System.out);

      boolean[] primes = new boolean[31624];
      Arrays.fill(primes, true);

      primes[0] = false;
      primes[1] = false;

      ArrayList<Integer> primesList = new ArrayList<Integer>(3401);

      for(int i = 2; i < primes.length; i++){
         if(primes[i]){
            primesList.add(i);
            for(int j = i*2; j < primes.length; j += i){
               primes[j] = false;
            }
         }
      }

      StringTokenizer st = new StringTokenizer(br.readLine(), " ");

      int l1 = Integer.parseInt(st.nextToken());
      int l2 = Integer.parseInt(st.nextToken());

      int cnt = 0;

      for(int i = 0; i < primesList.size(); i++){
         int c1 = 0;
         while(l1 % primesList.get(i) == 0){
            c1++;
            l1 /= primesList.get(i);
         }

         int c2 = 0;
         while(l2 % primesList.get(i) == 0){
            c2++;
            l2 /= primesList.get(i);
         }

         if(i < 3){
            cnt += Math.abs(c2-c1);
         } else if(c1 != c2){
            cnt = -1;
            break;
         }
      }

      if(l2 != l1){
         cnt = -1;
      }

      pw.println(cnt);

		br.close();
		pw.close();
	}

   public static void debug(Object o){
      if(DEBUG){
         System.out.println(o);
      }
   }
}

import java.util.Scanner;

public class Main{

	private static Scanner input;
	private static int a,b;
	private static int[] divs = {2,3,5,6};
	private static int[] values = {0,0,0,0,0,0};

	public static void main(String[] args) {
		input = new Scanner(System.in);
		a = input.nextInt();
		b = input.nextInt();
		int ia=0, ib=0;
		while(ia<4 || ib<4){
			if(ia<4){
				if(a%divs[ia] == 0){
					values[ia]++;
					a /= divs[ia];
				}else{
					ia++;
				}
			}
			if(ib<4){
				if(b%divs[ib] == 0){
					values[ib+3]++;
					b /= divs[ib];
				}else{
					ib++;
				}
			}
		}
		if(a == b){
			System.out.println(Math.abs(values[0]-values[3]) + Math.abs(values[1]-values[4]) + Math.abs(values[2]-values[5]));
		}
		else{
			System.out.println(-1);
		}

	}

}

import java.util.Scanner;

public class Main371b {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if (a == b) {
            System.out.println(0);
        } else {
            int aa[] = new int[3];
            int bb[] = new int[3];
            int a1 = a;
            int b1 = b;
            while (a % 2 == 0) {
                a = a / 2;
                aa[0]++;
            }
            while (a % 3 == 0) {
                a = a / 3;
                aa[1]++;
            }
            while (a % 5 == 0) {
                a = a / 5;
                aa[2]++;
            }
            while (b % 2 == 0) {
                b = b / 2;
                bb[0]++;
            }
            while (b % 3 == 0) {
                b = b / 3;
                bb[1]++;
            }
            while (b % 5 == 0) {
                b = b / 5;
                bb[2]++;
            }
            if (a != b) {
                System.out.println(-1);
            } else {
                int sum = aa[0] + aa[1] + aa[2] + bb[0] + bb[1] + bb[2];
                while (a1 % 2 == 0 && b1 % 2 == 0) {
                    sum -= 2;
                    a1=a1/2;
                    b1=b1/2;
                }
                while (a1 % 3 == 0 && b1 % 3 == 0) {
                    sum -= 2;
                    a1=a1/3;
                    b1=b1/3;
                }
                while (a1 % 5 == 0 && b1 % 5 == 0) {
                    sum -= 2;
                    a1=a1/5;
                    b1=b1/5;
                }
                System.out.println(sum);
            }
        }
    }
}

import java.io.*;
import java.util.*;

/**
 *
 * @author Altynbek.Nurgaziyev
 */
public class R218_D2_B {

        public int gcd(int a, int b) {
                if (b == 0) {
                        return a;
                } else {
                        return gcd(b, a % b);
                }
        }

        public int count(int x) {
                int c = 0;
                while (x > 1) {
                        boolean bool = false;
                        if (x % 5 == 0) {
                                x /= 5;
                                bool = true;
                                c++;
                        } else if (x % 3 == 0) {
                                x /= 3;
                                bool = true;
                                c++;
                        } else if (x % 2 == 0) {
                                x /= 2;
                                bool = true;
                                c++;
                        }
                        if (!bool) {
                                break;
                        }
                }
                if (x == 1) {
                        return c;
                }
                return -1;
        }

        public void solution() throws Exception {
                int a = in.nextInt();
                int b = in.nextInt();
                int g = gcd(a, b);
                int x = count(a / g);
                int y = count(b / g);
                if (x == -1 || y == -1) {
                        out.println(-1);
                } else {
                        out.println(x + y);
                }
        }

        Scanner in;
        PrintWriter out;
        String input, output;

        public void run() throws Exception {
                if (input != null) {
                        in = new Scanner(new FileReader(input));
                } else {
                        in = new Scanner(System.in);
                }

                if (output != null) {
                        out = new PrintWriter(new File(output));
                } else {
                        out = new PrintWriter(System.out);
                }

                solution();

                out.close();
        }

        public static void main(String[] args) throws Exception {
                new R218_D2_B().run();
        }

        public class Scanner {

                private BufferedReader br;
                private StringTokenizer st;

                public Scanner(InputStream is) {
                        br = new BufferedReader(new InputStreamReader(is));
                }

                public Scanner(FileReader fr) {
                        br = new BufferedReader(fr);
                }

                public String next() throws Exception {
                        while (st == null || !st.hasMoreTokens()) {
                                st = new StringTokenizer(br.readLine());
                        }
                        return st.nextToken();
                }

                public Integer nextInt() throws Exception {
                        return Integer.parseInt(next());
                }

                public Long nextLong() throws Exception {
                        return Long.parseLong(next());
                }

                public Double nextDouble() throws Exception {
                        return Double.parseDouble(next());
                }
        }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Rnd218B {

    private Rnd218B() throws IOException {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();

        int[] div1 = new int[3];
        int[] div2 = new int[3];
        int rem1 = helper(a, div1);
        int rem2 = helper(b, div2);
        if(rem1 != rem2) {
            out(-1);
            return;
        }
        int res = 0;
        for(int i = 0; i < 3; i++)
            res = res + Math.abs(div1[i] - div2[i]);
        out(res);

    }
    public int helper(int a, int[] x){
        int[] did = {2, 3, 5};
        for(int i = 0; i < did.length; i++) {
            int d = 0;
            while(a % did[i] == 0) {
                d++;
                a = a / did[i];
            }
            x[i] = d;
        }
        return a;
    }

    private int[] intarr(String s) {
        String[] q = s.split(" ");
        int n = q.length;
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(q[i]);
        }
        return a;
    }
    private static void out(Object x) {
        System.out.println(x);
    }
    public static void main(String[] args) throws IOException {
        new Rnd218B();
    }
}

import java.util.*;
import java.io.*;

public class A {
	FastScanner in;
	PrintWriter out;

	public int gcd(int a, int b) {
		while (a > 0 && b > 0) {
			if (a > b) {
				a = a % b;
			} else {
				b = b % a;
			}
		}
		return a+b;
	}

	public void solve() throws IOException {
		int a = in.nextInt();
		int b = in.nextInt();
		int g = gcd(a, b);
		a = a / g;
		b = b / g;
		int ans = 0;
		while (a % 2 == 0) {
			a = a / 2;
			ans++;
		}
		while (a % 3 == 0) {
			a = a / 3;
			ans++;
		}
		while (a % 5 == 0) {
			a = a / 5;
			ans++;
		}
		while (b % 2 == 0) {
			b = b / 2;
			ans++;
		}
		while (b % 3 == 0) {
			b = b / 3;
			ans++;
		}
		while (b % 5 == 0) {
			b = b / 5;
			ans++;
		}
		if (a != 1 || b != 1) {
			out.print(-1);
		} else {
			out.print(ans);
		}
	}

	public void run() {
		try {
			in = new FastScanner(System.in);
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(InputStream f) {
			try {
				br = new BufferedReader(new InputStreamReader(f));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			try {
				return br.readLine();
			} catch (Exception e) {
				return null;
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
	}

	public static void main(String[] arg) {
		new A().run();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution {

    private final static FastReader in = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);
    static int ans = Integer.MAX_VALUE;
    static HashSet<String> set=new HashSet<>();

    public static int solve(int a, int b) {
        if (a == b) {
            return 0;
        }
        DivBy(a, b, 0);
        if (ans != Integer.MAX_VALUE) {
            return ans;
        } else {
            return -1;
        }
    }

    static void DivBy(int a, int b, int r) {
        if (a == b) {
            if (r < ans) {
                ans = r;
            }
            return;
        }
        if(set.contains(a+""+b)){
            return;
        }
        if (a > b) {
            if (a % 2 == 0) {
                DivBy(a / 2, b, r + 1);
            }
            if (a % 3 == 0) {
                DivBy(a / 3, b, r + 1);
            }
            if (a % 5 == 0) {
                DivBy(a / 5, b, r + 1);
            }
        } else {
            if (b % 2 == 0) {
                DivBy(a, b / 2, r + 1);
            }
            if (b % 3 == 0) {
                DivBy(a, b / 3, r + 1);
            }
            if (b % 5 == 0) {
                DivBy(a, b / 5, r + 1);
            }
        }

       set.add(a+""+b);
    }

    public static void main(String[] args) {

        out.println(solve(in.nextInt(), in.nextInt()));
        out.close();
    }

    private static final class FastReader {
        private static BufferedReader BF;
        private static StringTokenizer ST;

        public FastReader() {
            BF = new BufferedReader(new InputStreamReader(System.in));
            ST = null;
        }

        public final String next() {
            while (ST == null || !ST.hasMoreTokens()) {
                try {
                    ST = new StringTokenizer(BF.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return ST.nextToken();

        }

        final int nextInt() {
            return Integer.parseInt(next());
        }

//        final long nextLong() {
//            return Long.parseLong(next());
//        }
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(bf.readLine().trim());
int a=Integer.parseInt(st.nextToken()),b=Integer.parseInt(st.nextToken());
int na2,na3,na5,nb2,nb3,nb5;
na2=na3=na5=nb2=nb3=nb5=0;
while(a%2==0)
{
	na2+=1;
	a=a/2;}
while(a%3==0)
{
	na3+=1;
	a=a/3;}
while(a%5==0)
{
	na5+=1;
	a=a/5;}
while(b%2==0)
{
	nb2+=1;
	b=b/2;}
while(b%3==0)
{
	nb3+=1;
	b=b/3;}
while(b%5==0)
{
	nb5+=1;
	b=b/5;}
if(a!=b)
	System.out.println(-1);
else {

	int min=0;
	min+=Math.abs(na2-nb2)+Math.abs(na3-nb3)+Math.abs(na5-nb5);
	System.out.println(min);
}
	}

}

import com.sun.jdi.ArrayReference;
import com.sun.source.tree.WhileLoopTree;

import java.io.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

public class CP {
    static long startTime;
    static long endTime;
    static Boolean [] prime ;
    static Scanner sc = new Scanner(System.in);
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static int lowerBound
            (Integer[] array, int length, int value) {
        int l = 0;
        int r = length;
        while (l < r) {
            int mid = (l + r) / 2;
            if (value < array[mid]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }
    public static long gcd(long a, long b){
        if (b == 0)
            return a;
        else return gcd(b, a % b);
    }
    public  static  long countDivs(long n ){
        int cn=0;
        long sqr = (long)Math.sqrt(n);
        for (long i = 1; i<=sqr ; ++i) {
            if(n%i==0){
                ++cn;
            }
        }
        cn*=2;
        if(sqr*sqr==n) cn--;
        return cn;

    }
    static void prime(int  x) {
        //sieve algorithm. nlog(log(n)).
        prime=new Boolean[ (x+1)];
        Arrays.fill(prime,true);
        prime[0] = prime[1] = false;
        for (int  i = 2; i * i <= x ; i++)
            if (prime[i])
                for (int  j = i * i; j <= x; j += i)
                    prime[j] = false;
    }
    static int[] sum;
    static void cumulitiveSum( int [] arr){
        sum = new int[arr.length];
        sum[0]=arr[0];
        for (int i = 1; i <arr.length; i++) {
            sum[i]=arr[i]+sum[i-1];
        }
    }
    static boolean isEven(long x ){
        return x % 2 == 0;
    }
    static boolean isPrime(long x ){
        boolean flag = true;
        int sqr = (int)Math.sqrt(x);
        if(x<2) return false;
        for (int i = 2; i <=sqr; i++) {
            if(x%i==0){
                flag=false;
                break;
            }
        }
        return flag;
    }
    static int  mex=0;
    static int mecfi(int arr[],int n  ){
        Arrays.sort(arr);
        for (int i = 0; i <n ; i++) {
            if(arr[i]==mex) {
                mex++;
            }
        }
        return mex;
    }
    public static void main(String [] args)   {
        startTime = System.currentTimeMillis();
       // int T = sc.nextInt();while (T--!=0)
        {
            solve();
        }
        endTime = System.currentTimeMillis();
        long duration= endTime-startTime;
        //System.out.println(duration);
    }
    public static void solve()  {
//////////////////////////////////////////////////////////////////////
       int x=sc.nextInt(),y=sc.nextInt();
       int []  fx = new int [8];
       int []  fy = new int [8];
        for (int i = 2; i <=7 ; i++) {
            while(x%i==0){
                fx[i]++;
                x/=i;
            }

        }
        for (int i = 2; i <=7 ; i++) {
            while(y%i==0){
               fy[i]++;
                y/=i;
            }

        }
        int ans=0;
        for (int i = 0; i <8; i++) {
            if(fx[i]!=fy[i]  ){
                if(i==5 || i==3 || i==2)
                ans+=Math.abs(fx[i]-fy[i]);
                else
                    {
                    System.out.println(-1);
                    return;
                    }
            }
        }
        if(x==y)
        System.out.println(ans);
        else System.out.println(-1);
///////////////////////////////////////////////////////////////////////
    }

}

import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

import static java.lang.Math.*;

public class CodeforcesA implements Runnable{

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch (Exception e){
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException{
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException{
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException{
        return Double.parseDouble(readString());
    }

    public static void main(String[] args){
        new Thread(null, new CodeforcesA(), "", 128 * (1L << 20)).start();
    }

    long timeBegin, timeEnd;

    void time(){
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory(){
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
    }

    void debug(Object... objects){
        if (DEBUG){
            for (Object o: objects){
                System.err.println(o.toString());
            }
        }
    }

    public void run(){
        try{
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            time();
            memory();
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    boolean DEBUG = false;

    void solve() throws IOException{

        int a = readInt();
        int b = readInt();

        int x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;

        while (a%2==0) {
            a/=2;
            x1++;
        }

        while (a%3==0) {
            a/=3;
            y1++;
        }

        while (a%5==0) {
            a/=5;
            z1++;
        }

        while (b%2==0) {
            b/=2;
            x2++;
        }

        while (b%3==0) {
            b/=3;
            y2++;
        }

        while (b%5==0) {
            b/=5;
            z2++;
        }

        if (a!=b) {
            out.println(-1);
            return;
        }

        int ans = Math.abs(x1-x2) + Math.abs(y1-y2) + Math.abs(z1-z2);
        out.println(ans);

    }
}

		import java.io.*;
		import java.util.*;
		public class Sample {
		    static int MAX = (int)1e6+1;
		    static int MOD=(int)1e9+7;
		    static int countt = 0;
			public static void main(String[] args) throws Exception{
				// TODO Auto-generated method stub
				//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
				Scanner input  = new Scanner(System.in);
				int a = input.nextInt();
				int b = input.nextInt();
				int count1[] = new int[3];
				int count2[] = new int[3];
				while(a%2 == 0) {a/=2;count1[0]++;}
				while(a%3 == 0) {a/=3;count1[1]++;}
				while(a%5 == 0) {a/=5;count1[2]++;}
				while(b%2 == 0) {b/=2;count2[0]++;}
				while(b%3 == 0) {b/=3;count2[1]++;}
				while(b%5 == 0) {b/=5;count2[2]++;}
				if(a == b) {
					int a2 = Math.min(count1[0], count2[0]);
					count1[0]-=a2;count2[0]-=a2;
					int a3 = Math.min(count1[1], count2[1]);
					count2[1]-=a3;count2[1]-=a3;
					int a5 = Math.min(count1[2], count2[2]);
					count1[2]-=a5;count2[2]-=a5;
					int count =0;
					for(int i =0;i<3;i++) {count+=count1[i];count+=count2[i];}
					System.out.println(count);
				}else System.out.println(-1);
			}
		}

//package ladderB;

import java.util.HashMap;
import java.util.Scanner;

public class foxDividingCheese {
	static int INF = (int)1e9;
	static HashMap<Integer, Integer> memo;
	static int gcd(int one, int two) {
		if(two==0)return one;
		return gcd(two, one%two);
	}
	static int minWays(int cur) {
		if(cur==1)
		{
			int ans = 0;
			memo.put(cur,ans);
			return ans;
		}
		if(memo.containsKey(cur))
			return memo.get(cur);
		int two = INF;
		int three =INF;
		int four =INF;
		int five = INF;
		if(cur%2==0)
			two = minWays(cur/2)+1;
		if(cur%3==0)
			three = minWays(cur/3)+1;
		if(cur%5==0)
			three = minWays(cur/5)+1;
		int min = Math.min(two, Math.min(three, Math.min(four, five)));
		if(min>=INF)
		{
			memo.put(cur,INF);
			return INF;
		}else {
			memo.put(cur, min);
			return min;
		}
	}
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int one = sc.nextInt();
	int two = sc.nextInt();
	int gcd = gcd(one,two);
	memo = new HashMap<Integer,Integer>();
	one/=gcd;
	two/=gcd;
	if(one ==two)
			System.out.println(0);
	else {
		int firstOne = minWays(one);
		int secondOne = minWays(two);
		//System.out.println(firstOne+" "+secondOne+" "+one+" "+two);
		if(firstOne==INF|| secondOne == INF)
			System.out.println(-1);
		else System.out.println(firstOne+secondOne);
	}
}
}

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		if (a == b) {
			System.out.println(0);
		} else {
			int a2 = f(a, 2);
			int a3 = f(a, 3);
			int a5 = f(a, 5);
			int b2 = f(b, 2);
			int b3 = f(b, 3);
			int b5 = f(b, 5);
			int min2 = Math.min(a2, b2);
			int min3 = Math.min(a3, b3);
			int min5 = Math.min(a5, b5);
			int ans = 0;
			if(a2 < b2){
				for(int i = 0; i < b2 - a2; i++){
					b/=2;
					ans++;
				}
			}else{
				for(int i = 0; i < a2 - b2; i++){
					a/=2;
					ans++;
				}
			}
			if(a3 < b3){
				for(int i = 0; i < b3 - a3; i++){
					b/=3;
					ans++;
				}
			}else{
				for(int i = 0; i < a3 - b3; i++){
					a/=3;
					ans++;
				}
			}
			if(a5 < b5){
				for(int i = 0; i < b5 - a5; i++){
					b/=5;
					ans++;
				}
			}else{
				for(int i = 0; i < a5 - b5; i++){
					a/=5;
					ans++;
				}
			}
			if(a == b){
				System.out.println(ans);
			}else{
				System.out.println(-1);
			}

		}
	}

	private static int f(int a, int i) {
		int ans = 0;
		int temp = a;
		while(temp % i == 0){
			temp /= i;
			ans++;
		}
		return ans;
	}

}

import java.text.ParseException;
import java.util.*;
import java.io.*;
import java.math.BigInteger;

import static java.lang.Math.*;

    public class solver {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;

    BufferedReader in;
    static PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
             in = new BufferedReader(new InputStreamReader(System.in));
             out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch (Exception e){
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException{
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException{
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException{
        return Double.parseDouble(readString());
    }

    public static void main(String[] args) throws IOException, ParseException{
        new solver().run();
    }

    long timeBegin, timeEnd;

    void time(){
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }
    int[] iMas(int n) throws IOException{
        int[] a=new int[n];
        for (int i=0;i<n;i++){
            a[i]=readInt();
        }
        return a;
    }
    void oMas(int[] a){
        for (int i=0;i<a.length;i++){
            out.println(a[i]);
        }
    }

    int gcd(int a,int b){
        if (b==0) return a;
        return gcd(b, a%b);
    }

    int fact235(int a){
        int k=0;
        while (a%5==0){
            k++;
            a/=5;
        }
        while (a%3==0){
            k++;
            a/=3;
        }
        while (a%2==0){
            k++;
            a/=2;
        }
        if (a==1) return k;else return -1;
    }

    void solve() throws IOException{

        int a=readInt();
        int b=readInt();

        int nod=gcd(a,b);
        int c=a/nod;
        int d=b/nod;
        if (fact235(c)==-1 || fact235(d)==-1){
            out.println(-1);
        }else{
            out.println(fact235(c)+fact235(d));
        }

    }

    public void run() throws IOException, ParseException{

        init();
        long h=System.currentTimeMillis();
        solve();
        System.err.println(System.currentTimeMillis()-h);
        out.close();
    }

}

import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.reflect.*;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		Task solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

interface Task {
	public void solve(int testNumber, InputReader in, OutputWriter out);
}

class TaskA implements Task {

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int p=Integer.MAX_VALUE;
		for (int i=0; i<4; i++) p=MiscUtils.min(p, in.readInt());
		int a=in.readInt(), b=in.readInt(), ret=0;
		for (int i=a; i<=b; i++) if (i<p) ret++;
		out.printLine(ret);
	}

}

class TaskB implements Task {

	int[] div={2, 3, 5};

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int a=in.readInt(), b=in.readInt(), g=IntegerUtils.gcd(a, b), ret=0;
		a/=g;
		b/=g;
		for (int i=0; i<3; i++) {
			while (a%div[i]==0) {
				a/=div[i];
				ret++;
			}
			while (b%div[i]==0) {
				b/=div[i];
				ret++;
			}
		}
		if (a==1 && b==1) out.printLine(ret);
		else out.printLine(-1);
	}

}

class TaskC implements Task {

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n=in.readInt();
		long ret=Long.MIN_VALUE;
		for (int i=MiscUtils.max(1, n-100); i<=n; i++) for (int j=i; j<=n; j++) for (int k=j; k<=n; k++)
			ret=MiscUtils.max(ret, IntegerUtils.lcm(IntegerUtils.lcm(i, j), k));
		out.printLine(ret);
	}

}

class TaskD implements Task {

	long[][] dp;
	List<List<Long>> list;

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n=in.readInt(), k=in.readInt(), mod=1000000007;
		dp=new long[k+1][n+1];
		Arrays.fill(dp[1], 1L);
		list=new ArrayList<List<Long>>();
		for (int i=0; i<=n; i++) list.add(IntegerUtils.getDivisors(i));
		for (int i=2; i<=k; i++) for (int j=1; j<=n; j++) for (long x: list.get(j)) dp[i][j]=(dp[i][j]+dp[i-1][(int)x])%mod;
		long ret=0L;
		for (int i=1; i<=n; i++) ret=(ret+dp[k][i])%mod;
		out.printLine(ret);
	}
}

class TaskE implements Task {

	public void solve(int testNumber, InputReader in, OutputWriter out) {

	}

}

class TaskF implements Task {

	public void solve(int testNumber, InputReader in, OutputWriter out) {

	}

}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(char[] array) {
		writer.print(array);
	}

	public void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void print(int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(array[i]);
		}
	}

	public void print(long[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(array[i]);
		}
	}

	public void print(Collection<Integer> collection) {
		boolean first = true;
		for (int value : collection) {
			if (first)
				first = false;
			else
				writer.print(' ');
			writer.print(value);
		}
	}

	public void printLine(int[] array) {
		print(array);
		writer.println();
	}

	public void printLine(long[] array) {
		print(array);
		writer.println();
	}

	public void printLine(Collection<Integer> collection) {
		print(collection);
		writer.println();
	}

	public void printLine() {
		writer.println();
	}

	public void printLine(Object... objects) {
		print(objects);
		writer.println();
	}

	public void print(char i) {
		writer.print(i);
	}

	public void printLine(char i) {
		writer.println(i);
	}

	public void printLine(char[] array) {
		writer.println(array);
	}

	public void printFormat(String format, Object... objects) {
		writer.printf(format, objects);
	}

	public void close() {
		writer.close();
	}

	public void flush() {
		writer.flush();
	}

	public void print(long i) {
		writer.print(i);
	}

	public void printLine(long i) {
		writer.println(i);
	}

	public void print(int i) {
		writer.print(i);
	}

	public void printLine(int i) {
		writer.println(i);
	}
}

class InputReader {
	private boolean finished = false;

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int peek() {
		if (numChars == -1)
			return -1;
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				return -1;
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			if (Character.isValidCodePoint(c))
				res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	public static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private String readLine0() {
		StringBuilder buf = new StringBuilder();
		int c = read();
		while (c != '\n' && c != -1) {
			if (c != '\r')
				buf.appendCodePoint(c);
			c = read();
		}
		return buf.toString();
	}

	public String readLine() {
		String s = readLine0();
		while (s.trim().length() == 0)
			s = readLine0();
		return s;
	}

	public String readLine(boolean ignoreEmptyLines) {
		if (ignoreEmptyLines)
			return readLine();
		else
			return readLine0();
	}

	public BigInteger readBigInteger() {
		try {
			return new BigInteger(readString());
		} catch (NumberFormatException e) {
			throw new InputMismatchException();
		}
	}

	public char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}

	public double readDouble() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		double res = 0;
		while (!isSpaceChar(c) && c != '.') {
			if (c == 'e' || c == 'E')
				return res * Math.pow(10, readInt());
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		}
		if (c == '.') {
			c = read();
			double m = 1;
			while (!isSpaceChar(c)) {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				m /= 10;
				res += (c - '0') * m;
				c = read();
			}
		}
		return res * sgn;
	}

	public boolean isExhausted() {
		int value;
		while (isSpaceChar(value = peek()) && value != -1)
			read();
		return value == -1;
	}

	public String next() {
		return readString();
	}

	public SpaceCharFilter getFilter() {
		return filter;
	}

	public void setFilter(SpaceCharFilter filter) {
		this.filter = filter;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class IOUtils {
	public static Pair<Integer, Integer> readIntPair(InputReader in) {
		int first = in.readInt();
		int second = in.readInt();
		return Pair.makePair(first, second);
	}

	public static Pair<Long, Long> readLongPair(InputReader in) {
		long first = in.readLong();
		long second = in.readLong();
		return Pair.makePair(first, second);
	}

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}

	public static long[] readLongArray(InputReader in, int size) {
		long[] array = new long[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readLong();
		return array;
	}

	public static double[] readDoubleArray(InputReader in, int size) {
		double[] array = new double[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readDouble();
		return array;
	}

	public static String[] readStringArray(InputReader in, int size) {
		String[] array = new String[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readString();
		return array;
	}

	public static char[] readCharArray(InputReader in, int size) {
		char[] array = new char[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readCharacter();
		return array;
	}

	public static Pair<Integer, Integer>[] readIntPairArray(InputReader in,
			int size) {
		@SuppressWarnings({ "unchecked" })
		Pair<Integer, Integer>[] result = new Pair[size];
		for (int i = 0; i < size; i++)
			result[i] = readIntPair(in);
		return result;
	}

	public static Pair<Long, Long>[] readLongPairArray(InputReader in, int size) {
		@SuppressWarnings({ "unchecked" })
		Pair<Long, Long>[] result = new Pair[size];
		for (int i = 0; i < size; i++)
			result[i] = readLongPair(in);
		return result;
	}

	public static void readIntArrays(InputReader in, int[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readInt();
		}
	}

	public static void readLongArrays(InputReader in, long[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readLong();
		}
	}

	public static void readDoubleArrays(InputReader in, double[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readDouble();
		}
	}

	public static char[][] readTable(InputReader in, int rowCount,
			int columnCount) {
		char[][] table = new char[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readCharArray(in, columnCount);
		return table;
	}

	public static int[][] readIntTable(InputReader in, int rowCount,
			int columnCount) {
		int[][] table = new int[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readIntArray(in, columnCount);
		return table;
	}

	public static double[][] readDoubleTable(InputReader in, int rowCount,
			int columnCount) {
		double[][] table = new double[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readDoubleArray(in, columnCount);
		return table;
	}

	public static long[][] readLongTable(InputReader in, int rowCount,
			int columnCount) {
		long[][] table = new long[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readLongArray(in, columnCount);
		return table;
	}

	public static String[][] readStringTable(InputReader in, int rowCount,
			int columnCount) {
		String[][] table = new String[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readStringArray(in, columnCount);
		return table;
	}

	public static String readText(InputReader in) {
		StringBuilder result = new StringBuilder();
		while (true) {
			int character = in.read();
			if (character == '\r')
				continue;
			if (character == -1)
				break;
			result.append((char) character);
		}
		return result.toString();
	}

	public static void readStringArrays(InputReader in, String[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readString();
		}
	}

	public static void printTable(OutputWriter out, char[][] table) {
		for (char[] row : table)
			out.printLine(new String(row));
	}
}

class ArrayUtils {
	private static int[] tempInt = new int[0];
	private static long[] tempLong = new long[0];

	public static Integer[] generateOrder(int size) {
		Integer[] order = new Integer[size];
		for (int i = 0; i < size; i++)
			order[i] = i;
		return order;
	}

	public static void fill(short[][] array, short value) {
		for (short[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(long[][] array, long value) {
		for (long[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(double[][] array, double value) {
		for (double[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(double[][][] array, double value) {
		for (double[][] row : array)
			fill(row, value);
	}

	public static void fill(double[][][][] array, double value) {
		for (double[][][] row : array)
			fill(row, value);
	}

	public static void fill(double[][][][][] array, double value) {
		for (double[][][][] row : array)
			fill(row, value);
	}

	public static void fill(long[][][] array, long value) {
		for (long[][] row : array)
			fill(row, value);
	}

	public static void fill(long[][][][] array, long value) {
		for (long[][][] row : array)
			fill(row, value);
	}

	public static void fill(long[][][][][] array, long value) {
		for (long[][][][] row : array)
			fill(row, value);
	}

	public static void fillColumn(long[][] array, int index, long value) {
		for (long[] row : array)
			row[index] = value;
	}

	public static void fillColumn(int[][] array, int index, int value) {
		for (int[] row : array)
			row[index] = value;
	}

	public static void fill(int[][] array, int value) {
		for (int[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(boolean[][] array, boolean value) {
		for (boolean[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(boolean[][][] array, boolean value) {
		for (boolean[][] row : array)
			fill(row, value);
	}

	public static long sumArray(int[] array) {
		long result = 0;
		for (int element : array)
			result += element;
		return result;
	}

	public static int[] range(int from, int to) {
		int[] result = new int[Math.max(from, to) - Math.min(from, to) + 1];
		int index = 0;
		if (to > from) {
			for (int i = from; i <= to; i++)
				result[index++] = i;
		} else {
			for (int i = from; i >= to; i--)
				result[index++] = i;
		}
		return result;
	}

	public static void fill(int[][][] array, int value) {
		for (int[][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][] array, short value) {
		for (short[][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(int[][][][] array, int value) {
		for (int[][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][][] array, short value) {
		for (short[][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(int[][][][][] array, int value) {
		for (int[][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][][][] array, short value) {
		for (short[][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(int[][][][][][] array, int value) {
		for (int[][][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][][][][] array, short value) {
		for (short[][][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(int[][][][][][][] array, int value) {
		for (int[][][][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][][][][][] array, short value) {
		for (short[][][][][][] subArray : array)
			fill(subArray, value);
	}

	public static Integer[] order(int size, Comparator<Integer> comparator) {
		Integer[] order = generateOrder(size);
		Arrays.sort(order, comparator);
		return order;
	}

	public static <T> void fill(T[][] array, T value) {
		for (T[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(char[][] array, char value) {
		for (char[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(byte[][] array, byte value) {
		for (byte[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(byte[][][] array, byte value) {
		for (byte[][] row : array)
			fill(row, value);
	}

	public static void fill(byte[][][][] array, byte value) {
		for (byte[][][] row : array)
			fill(row, value);
	}

	public static long multiply(int[] first, int[] second) {
		long result = 0;
		for (int i = 0; i < first.length; i++)
			result += (long) first[i] * second[i];
		return result;
	}

	public static int[] createOrder(int size) {
		int[] order = new int[size];
		for (int i = 0; i < size; i++)
			order[i] = i;
		return order;
	}

	public static int[] sort(int[] array, IntComparator comparator) {
		return sort(array, 0, array.length, comparator);
	}

	public static int[] sort(int[] array, int from, int to,
			IntComparator comparator) {
		Integer[] intArray = new Integer[to - from];
		for (int i = from; i < to; i++)
			intArray[i - from] = array[i];
		Arrays.sort(intArray, comparator);
		for (int i=from; i<to; i++) array[i]=intArray[i-from];
		return array;
	}

	private static void ensureCapacityInt(int size) {
		if (tempInt.length >= size)
			return;
		size = Math.max(size, tempInt.length << 1);
		tempInt = new int[size];
	}

	private static void ensureCapacityLong(int size) {
		if (tempLong.length >= size)
			return;
		size = Math.max(size, tempLong.length << 1);
		tempLong = new long[size];
	}

	private static void sortImpl(int[] array, int from, int to, int[] temp,
			int fromTemp, int toTemp, IntComparator comparator) {
		if (to - from <= 1)
			return;
		int middle = (to - from) >> 1;
		int tempMiddle = fromTemp + middle;
		sortImpl(temp, fromTemp, tempMiddle, array, from, from + middle,
				comparator);
		sortImpl(temp, tempMiddle, toTemp, array, from + middle, to, comparator);
		int index = from;
		int index1 = fromTemp;
		int index2 = tempMiddle;
		while (index1 < tempMiddle && index2 < toTemp) {
			if (comparator.compare(temp[index1], temp[index2]) <= 0)
				array[index++] = temp[index1++];
			else
				array[index++] = temp[index2++];
		}
		if (index1 != tempMiddle)
			System.arraycopy(temp, index1, array, index, tempMiddle - index1);
		if (index2 != toTemp)
			System.arraycopy(temp, index2, array, index, toTemp - index2);
	}

	public static int[] order(final int[] array) {
		return sort(createOrder(array.length), new IntComparator() {
			public int compare(Integer first, Integer second) {
				if (array[first] < array[second])
					return -1;
				if (array[first] > array[second])
					return 1;
				return 0;
			}
		});
	}

	public static int[] order(final long[] array) {
		return sort(createOrder(array.length), new IntComparator() {
			public int compare(Integer first, Integer second) {
				if (array[first] < array[second])
					return -1;
				if (array[first] > array[second])
					return 1;
				return 0;
			}
		});
	}

	public static int[] unique(int[] array) {
		return unique(array, 0, array.length);
	}

	public static int[] unique(int[] array, int from, int to) {
		if (from == to)
			return new int[0];
		int count = 1;
		for (int i = from + 1; i < to; i++) {
			if (array[i] != array[i - 1])
				count++;
		}
		int[] result = new int[count];
		result[0] = array[from];
		int index = 1;
		for (int i = from + 1; i < to; i++) {
			if (array[i] != array[i - 1])
				result[index++] = array[i];
		}
		return result;
	}

	public static char[] unique(char[] array) {
		return unique(array, 0, array.length);
	}

	public static char[] unique(char[] array, int from, int to) {
		if (from == to)
			return new char[0];
		int count = 1;
		for (int i = from + 1; i < to; i++) {
			if (array[i] != array[i - 1])
				count++;
		}
		char[] result = new char[count];
		result[0] = array[from];
		int index = 1;
		for (int i = from + 1; i < to; i++) {
			if (array[i] != array[i - 1])
				result[index++] = array[i];
		}
		return result;
	}

	public static int maxElement(int[] array) {
		return maxElement(array, 0, array.length);
	}

	public static int maxElement(int[] array, int from, int to) {
		int result = Integer.MIN_VALUE;
		for (int i = from; i < to; i++)
			result = Math.max(result, array[i]);
		return result;
	}

	public static int[] order(final double[] array) {
		return sort(createOrder(array.length), new IntComparator() {
			public int compare(Integer first, Integer second) {
				return Double.compare(array[first], array[second]);
			}
		});
	}

	public static int[] reversePermutation(int[] permutation) {
		int[] result = new int[permutation.length];
		for (int i = 0; i < permutation.length; i++)
			result[permutation[i]] = i;
		return result;
	}

	public static void reverse(int[] array) {
		for (int i = 0, j = array.length - 1; i < j; i++, j--) {
			int temp = array[i];
			array[i] = array[j];
			array[j] = temp;
		}
	}

	public static void reverse(char[] array) {
		for (int i = 0, j = array.length - 1; i < j; i++, j--) {
			char temp = array[i];
			array[i] = array[j];
			array[j] = temp;
		}
	}

	private static long maxElement(long[] array, int from, int to) {
		long result = Long.MIN_VALUE;
		for (int i = from; i < to; i++)
			result = Math.max(result, array[i]);
		return result;
	}

	public static int minPosition(int[] array) {
		return minPosition(array, 0, array.length);
	}

	public static int maxPosition(int[] array) {
		return maxPosition(array, 0, array.length);
	}

	public static int minPosition(int[] array, int from, int to) {
		if (from >= to)
			return -1;
		int min = array[from];
		int result = from;
		for (int i = from + 1; i < to; i++) {
			if (array[i] < min) {
				min = array[i];
				result = i;
			}
		}
		return result;
	}

	public static int maxPosition(int[] array, int from, int to) {
		if (from >= to)
			return -1;
		int max = array[from];
		int result = from;
		for (int i = from + 1; i < to; i++) {
			if (array[i] > max) {
				max = array[i];
				result = i;
			}
		}
		return result;
	}

	public static int[] multiplyPermutations(int[] first, int[] second) {
		int count = first.length;
		int[] result = new int[count];
		for (int i = 0; i < count; i++) {
			result[i] = first[second[i]];
		}
		return result;
	}

	public static int[] compress(int[]... arrays) {
		int totalLength = 0;
		for (int[] array : arrays)
			totalLength += array.length;
		int[] all = new int[totalLength];
		int delta = 0;
		for (int[] array : arrays) {
			System.arraycopy(array, 0, all, delta, array.length);
			delta += array.length;
		}
		sort(all, IntComparator.DEFAULT);
		all = unique(all);
		for (int[] array : arrays) {
			for (int i = 0; i < array.length; i++)
				array[i] = Arrays.binarySearch(all, array[i]);
		}
		return all;
	}

	public static int minElement(int[] array) {
		return array[minPosition(array)];
	}

	public static long[] partialSums(int[] array) {
		long[] result = new long[array.length + 1];
		for (int i = 0; i < array.length; i++)
			result[i + 1] = result[i] + array[i];
		return result;
	}

	public static void orderBy(int[] base, int[]... arrays) {
		int[] order = ArrayUtils.order(base);
		order(order, base);
		for (int[] array : arrays)
			order(order, array);
	}

	public static void orderBy(long[] base, long[]... arrays) {
		int[] order = ArrayUtils.order(base);
		order(order, base);
		for (long[] array : arrays)
			order(order, array);
	}

	public static void order(int[] order, int[] array) {
		ensureCapacityInt(order.length);
		for (int i = 0; i < order.length; i++)
			tempInt[i] = array[order[i]];
		System.arraycopy(tempInt, 0, array, 0, array.length);
	}

	public static void order(int[] order, long[] array) {
		ensureCapacityLong(order.length);
		for (int i = 0; i < order.length; i++)
			tempLong[i] = array[order[i]];
		System.arraycopy(tempLong, 0, array, 0, array.length);
	}

	public static long[] asLong(int[] array) {
		long[] result = new long[array.length];
		for (int i = 0; i < array.length; i++)
			result[i] = array[i];
		return result;
	}

	public static int count(int[] array, int value) {
		int result = 0;
		for (int i : array) {
			if (i == value)
				result++;
		}
		return result;
	}

	public static int count(char[] array, char value) {
		int result = 0;
		for (char i : array) {
			if (i == value)
				result++;
		}
		return result;
	}

	public static int count(boolean[] array, boolean value) {
		int result = 0;
		for (boolean i : array) {
			if (i == value)
				result++;
		}
		return result;
	}

	public static int[] merge(int[] first, int[] second) {
		int[] result = new int[first.length + second.length];
		int firstIndex = 0;
		int secondIndex = 0;
		int index = 0;
		while (firstIndex < first.length && secondIndex < second.length) {
			if (first[firstIndex] < second[secondIndex])
				result[index++] = first[firstIndex++];
			else
				result[index++] = second[secondIndex++];
		}
		System.arraycopy(first, firstIndex, result, index, first.length
				- firstIndex);
		System.arraycopy(second, secondIndex, result, index, second.length
				- secondIndex);
		return result;
	}

	public static boolean nextPermutation(int[] array) {
		return nextPermutation(array, IntComparator.DEFAULT);
	}

	private static boolean nextPermutation(int[] array, IntComparator comparator) {
		int size = array.length;
		int last = array[size - 1];
		for (int i = size - 2; i >= 0; i--) {
			int current = array[i];
			if (comparator.compare(last, current) > 0) {
				for (int j = size - 1; j > i; j--) {
					if (comparator.compare(array[j], current) > 0) {
						swap(array, i, j);
						inPlaceReverse(array, i + 1, size);
						return true;
					}
				}
			}
			last = current;
		}
		return false;
	}

	private static void inPlaceReverse(int[] array, int first, int second) {
		for (int i = first, j = second - 1; i < j; i++, j--)
			swap(array, i, j);
	}

	private static void swap(int[] array, int first, int second) {
		if (first == second)
			return;
		int temp = array[first];
		array[first] = array[second];
		array[second] = temp;
	}

	public static <V> void reverse(V[] array) {
		for (int i = 0, j = array.length - 1; i < j; i++, j--) {
			V temp = array[i];
			array[i] = array[j];
			array[j] = temp;
		}
	}

	public static IntComparator compareBy(final int[]... arrays) {
		return new IntComparator() {
			public int compare(Integer first, Integer second) {
				for (int[] array : arrays) {
					if (array[first] != array[second])
						return Integer.compare(array[first], array[second]);
				}
				return 0;
			}
		};
	}

	public static long minElement(long[] array) {
		return array[minPosition(array)];
	}

	public static long maxElement(long[] array) {
		return array[maxPosition(array)];
	}

	public static int minPosition(long[] array) {
		return minPosition(array, 0, array.length);
	}

	public static int maxPosition(long[] array) {
		return maxPosition(array, 0, array.length);
	}

	public static int minPosition(long[] array, int from, int to) {
		if (from >= to)
			return -1;
		long min = array[from];
		int result = from;
		for (int i = from + 1; i < to; i++) {
			if (array[i] < min) {
				min = array[i];
				result = i;
			}
		}
		return result;
	}

	public static int maxPosition(long[] array, int from, int to) {
		if (from >= to)
			return -1;
		long max = array[from];
		int result = from;
		for (int i = from + 1; i < to; i++) {
			if (array[i] > max) {
				max = array[i];
				result = i;
			}
		}
		return result;
	}

	public static int[] createArray(int count, int value) {
		int[] array = new int[count];
		Arrays.fill(array, value);
		return array;
	}

	public static long[] createArray(int count, long value) {
		long[] array = new long[count];
		Arrays.fill(array, value);
		return array;
	}

	public static double[] createArray(int count, double value) {
		double[] array = new double[count];
		Arrays.fill(array, value);
		return array;
	}

	public static boolean[] createArray(int count, boolean value) {
		boolean[] array = new boolean[count];
		Arrays.fill(array, value);
		return array;
	}

	public static char[] createArray(int count, char value) {
		char[] array = new char[count];
		Arrays.fill(array, value);
		return array;
	}

	public static <T> T[] createArray(int count, T value) {
		@SuppressWarnings("unchecked")
		T[] array = (T[]) Array.newInstance(value.getClass(), count);
		Arrays.fill(array, value);
		return array;
	}
}

class Graph {
	public static final int REMOVED_BIT = 0;

	protected int vertexCount;
	protected int edgeCount;

	private int[] firstOutbound;
	private int[] firstInbound;

	private Edge[] edges;
	private int[] nextInbound;
	private int[] nextOutbound;
	private int[] from;
	private int[] to;
	private long[] weight;
	private long[] capacity;
	private int[] reverseEdge;
	private int[] flags;

	public Graph(int vertexCount) {
		this(vertexCount, vertexCount);
	}

	public Graph(int vertexCount, int edgeCapacity) {
		this.vertexCount = vertexCount;
		firstOutbound = new int[vertexCount];
		Arrays.fill(firstOutbound, -1);

		from = new int[edgeCapacity];
		to = new int[edgeCapacity];
		nextOutbound = new int[edgeCapacity];
		flags = new int[edgeCapacity];
	}

	public static Graph createGraph(int vertexCount, int[] from, int[] to) {
		Graph graph = new Graph(vertexCount, from.length);
		for (int i = 0; i < from.length; i++)
			graph.addSimpleEdge(from[i], to[i]);
		return graph;
	}

	public static Graph createWeightedGraph(int vertexCount, int[] from,
			int[] to, long[] weight) {
		Graph graph = new Graph(vertexCount, from.length);
		for (int i = 0; i < from.length; i++)
			graph.addWeightedEdge(from[i], to[i], weight[i]);
		return graph;
	}

	public static Graph createFlowGraph(int vertexCount, int[] from, int[] to,
			long[] capacity) {
		Graph graph = new Graph(vertexCount, from.length * 2);
		for (int i = 0; i < from.length; i++)
			graph.addFlowEdge(from[i], to[i], capacity[i]);
		return graph;
	}

	public static Graph createFlowWeightedGraph(int vertexCount, int[] from,
			int[] to, long[] weight, long[] capacity) {
		Graph graph = new Graph(vertexCount, from.length * 2);
		for (int i = 0; i < from.length; i++)
			graph.addFlowWeightedEdge(from[i], to[i], weight[i], capacity[i]);
		return graph;
	}

	public static Graph createTree(int[] parent) {
		Graph graph = new Graph(parent.length + 1, parent.length);
		for (int i = 0; i < parent.length; i++)
			graph.addSimpleEdge(parent[i], i + 1);
		return graph;
	}

	public int addEdge(int fromID, int toID, long weight, long capacity,
			int reverseEdge) {
		ensureEdgeCapacity(edgeCount + 1);
		if (firstOutbound[fromID] != -1)
			nextOutbound[edgeCount] = firstOutbound[fromID];
		else
			nextOutbound[edgeCount] = -1;
		firstOutbound[fromID] = edgeCount;
		if (firstInbound != null) {
			if (firstInbound[toID] != -1)
				nextInbound[edgeCount] = firstInbound[toID];
			else
				nextInbound[edgeCount] = -1;
			firstInbound[toID] = edgeCount;
		}
		this.from[edgeCount] = fromID;
		this.to[edgeCount] = toID;
		if (capacity != 0) {
			if (this.capacity == null)
				this.capacity = new long[from.length];
			this.capacity[edgeCount] = capacity;
		}
		if (weight != 0) {
			if (this.weight == null)
				this.weight = new long[from.length];
			this.weight[edgeCount] = weight;
		}
		if (reverseEdge != -1) {
			if (this.reverseEdge == null) {
				this.reverseEdge = new int[from.length];
				Arrays.fill(this.reverseEdge, 0, edgeCount, -1);
			}
			this.reverseEdge[edgeCount] = reverseEdge;
		}
		if (edges != null)
			edges[edgeCount] = createEdge(edgeCount);
		return edgeCount++;
	}

	protected final GraphEdge createEdge(int id) {
		return new GraphEdge(id);
	}

	public final int addFlowWeightedEdge(int from, int to, long weight,
			long capacity) {
		if (capacity == 0) {
			return addEdge(from, to, weight, 0, -1);
		} else {
			int lastEdgeCount = edgeCount;
			addEdge(to, from, -weight, 0, lastEdgeCount + entriesPerEdge());
			return addEdge(from, to, weight, capacity, lastEdgeCount);
		}
	}

	protected int entriesPerEdge() {
		return 1;
	}

	public final int addFlowEdge(int from, int to, long capacity) {
		return addFlowWeightedEdge(from, to, 0, capacity);
	}

	public final int addWeightedEdge(int from, int to, long weight) {
		return addFlowWeightedEdge(from, to, weight, 0);
	}

	public final int addSimpleEdge(int from, int to) {
		return addWeightedEdge(from, to, 0);
	}

	public final int vertexCount() {
		return vertexCount;
	}

	public final int edgeCount() {
		return edgeCount;
	}

	protected final int edgeCapacity() {
		return from.length;
	}

	public final Edge edge(int id) {
		initEdges();
		return edges[id];
	}

	public final int firstOutbound(int vertex) {
		int id = firstOutbound[vertex];
		while (id != -1 && isRemoved(id))
			id = nextOutbound[id];
		return id;
	}

	public final int nextOutbound(int id) {
		id = nextOutbound[id];
		while (id != -1 && isRemoved(id))
			id = nextOutbound[id];
		return id;
	}

	public final int firstInbound(int vertex) {
		initInbound();
		int id = firstInbound[vertex];
		while (id != -1 && isRemoved(id))
			id = nextInbound[id];
		return id;
	}

	public final int nextInbound(int id) {
		initInbound();
		id = nextInbound[id];
		while (id != -1 && isRemoved(id))
			id = nextInbound[id];
		return id;
	}

	public final int source(int id) {
		return from[id];
	}

	public final int destination(int id) {
		return to[id];
	}

	public final long weight(int id) {
		if (weight == null)
			return 0;
		return weight[id];
	}

	public final long capacity(int id) {
		if (capacity == null)
			return 0;
		return capacity[id];
	}

	public final long flow(int id) {
		if (reverseEdge == null)
			return 0;
		return capacity[reverseEdge[id]];
	}

	public final void pushFlow(int id, long flow) {
		if (flow == 0)
			return;
		if (flow > 0) {
			if (capacity(id) < flow)
				throw new IllegalArgumentException("Not enough capacity");
		} else {
			if (flow(id) < -flow)
				throw new IllegalArgumentException("Not enough capacity");
		}
		capacity[id] -= flow;
		capacity[reverseEdge[id]] += flow;
	}

	public int transposed(int id) {
		return -1;
	}

	public final int reverse(int id) {
		if (reverseEdge == null)
			return -1;
		return reverseEdge[id];
	}

	public final void addVertices(int count) {
		ensureVertexCapacity(vertexCount + count);
		Arrays.fill(firstOutbound, vertexCount, vertexCount + count, -1);
		if (firstInbound != null)
			Arrays.fill(firstInbound, vertexCount, vertexCount + count, -1);
		vertexCount += count;
	}

	protected final void initEdges() {
		if (edges == null) {
			edges = new Edge[from.length];
			for (int i = 0; i < edgeCount; i++)
				edges[i] = createEdge(i);
		}
	}

	public final void removeVertex(int vertex) {
		int id = firstOutbound[vertex];
		while (id != -1) {
			removeEdge(id);
			id = nextOutbound[id];
		}
		initInbound();
		id = firstInbound[vertex];
		while (id != -1) {
			removeEdge(id);
			id = nextInbound[id];
		}
	}

	private void initInbound() {
		if (firstInbound == null) {
			firstInbound = new int[firstOutbound.length];
			Arrays.fill(firstInbound, 0, vertexCount, -1);
			nextInbound = new int[from.length];
			for (int i = 0; i < edgeCount; i++) {
				nextInbound[i] = firstInbound[to[i]];
				firstInbound[to[i]] = i;
			}
		}
	}

	public final boolean flag(int id, int bit) {
		return (flags[id] >> bit & 1) != 0;
	}

	public final void setFlag(int id, int bit) {
		flags[id] |= 1 << bit;
	}

	public final void removeFlag(int id, int bit) {
		flags[id] &= -1 - (1 << bit);
	}

	public final void removeEdge(int id) {
		setFlag(id, REMOVED_BIT);
	}

	public final void restoreEdge(int id) {
		removeFlag(id, REMOVED_BIT);
	}

	public final boolean isRemoved(int id) {
		return flag(id, REMOVED_BIT);
	}

	public final Iterable<Edge> outbound(final int id) {
		initEdges();
		return new Iterable<Edge>() {
			public Iterator<Edge> iterator() {
				return new EdgeIterator(id, firstOutbound, nextOutbound);
			}
		};
	}

	public final Iterable<Edge> inbound(final int id) {
		initEdges();
		initInbound();
		return new Iterable<Edge>() {
			public Iterator<Edge> iterator() {
				return new EdgeIterator(id, firstInbound, nextInbound);
			}
		};
	}

	protected void ensureEdgeCapacity(int size) {
		if (from.length < size) {
			int newSize = Math.max(size, 2 * from.length);
			if (edges != null)
				edges = resize(edges, newSize);
			from = resize(from, newSize);
			to = resize(to, newSize);
			nextOutbound = resize(nextOutbound, newSize);
			if (nextInbound != null)
				nextInbound = resize(nextInbound, newSize);
			if (weight != null)
				weight = resize(weight, newSize);
			if (capacity != null)
				capacity = resize(capacity, newSize);
			if (reverseEdge != null)
				reverseEdge = resize(reverseEdge, newSize);
			flags = resize(flags, newSize);
		}
	}

	private void ensureVertexCapacity(int size) {
		if (firstOutbound.length < size) {
			int newSize = Math.max(size, 2 * from.length);
			firstOutbound = resize(firstOutbound, newSize);
			if (firstInbound != null)
				firstInbound = resize(firstInbound, newSize);
		}
	}

	protected final int[] resize(int[] array, int size) {
		int[] newArray = new int[size];
		System.arraycopy(array, 0, newArray, 0, array.length);
		return newArray;
	}

	private long[] resize(long[] array, int size) {
		long[] newArray = new long[size];
		System.arraycopy(array, 0, newArray, 0, array.length);
		return newArray;
	}

	private Edge[] resize(Edge[] array, int size) {
		Edge[] newArray = new Edge[size];
		System.arraycopy(array, 0, newArray, 0, array.length);
		return newArray;
	}

	public final boolean isSparse() {
		return vertexCount == 0 || edgeCount * 20 / vertexCount <= vertexCount;
	}

	protected class GraphEdge implements Edge {
		protected int id;

		protected GraphEdge(int id) {
			this.id = id;
		}

		public int getSource() {
			return source(id);
		}

		public int getDestination() {
			return destination(id);
		}

		public long getWeight() {
			return weight(id);
		}

		public long getCapacity() {
			return capacity(id);
		}

		public long getFlow() {
			return flow(id);
		}

		public void pushFlow(long flow) {
			Graph.this.pushFlow(id, flow);
		}

		public boolean getFlag(int bit) {
			return flag(id, bit);
		}

		public void setFlag(int bit) {
			Graph.this.setFlag(id, bit);
		}

		public void removeFlag(int bit) {
			Graph.this.removeFlag(id, bit);
		}

		public int getTransposedID() {
			return transposed(id);
		}

		public Edge getTransposedEdge() {
			int reverseID = getTransposedID();
			if (reverseID == -1)
				return null;
			initEdges();
			return edge(reverseID);
		}

		public int getReverseID() {
			return reverse(id);
		}

		public Edge getReverseEdge() {
			int reverseID = getReverseID();
			if (reverseID == -1)
				return null;
			initEdges();
			return edge(reverseID);
		}

		public int getID() {
			return id;
		}

		public void remove() {
			removeEdge(id);
		}

		public void restore() {
			restoreEdge(id);
		}
	}

	public class EdgeIterator implements Iterator<Edge> {
		private int edgeID;
		private final int[] next;
		private int lastID = -1;

		public EdgeIterator(int id, int[] first, int[] next) {
			this.next = next;
			edgeID = nextEdge(first[id]);
		}

		private int nextEdge(int id) {
			while (id != -1 && isRemoved(id))
				id = next[id];
			return id;
		}

		public boolean hasNext() {
			return edgeID != -1;
		}

		public Edge next() {
			if (edgeID == -1)
				throw new NoSuchElementException();
			lastID = edgeID;
			edgeID = nextEdge(next[lastID]);
			return edges[lastID];
		}

		public void remove() {
			if (lastID == -1)
				throw new IllegalStateException();
			removeEdge(lastID);
			lastID = -1;
		}
	}

}

class MiscUtils {
	public static final int[] DX4 = { 1, 0, -1, 0 };
	public static final int[] DY4 = { 0, -1, 0, 1 };
	public static final int[] DX8 = { 1, 1, 1, 0, -1, -1, -1, 0 };
	public static final int[] DY8 = { -1, 0, 1, 1, 1, 0, -1, -1 };
	public static final int[] DX_KNIGHT = { 2, 1, -1, -2, -2, -1, 1, 2 };
	public static final int[] DY_KNIGHT = { 1, 2, 2, 1, -1, -2, -2, -1 };

	private static final String[] ROMAN_TOKENS = { "M", "CM", "D", "CD", "C",
			"XC", "L", "XL", "X", "IX", "V", "IV", "I" };
	private static final int[] ROMAN_VALUES = { 1000, 900, 500, 400, 100, 90,
			50, 40, 10, 9, 5, 4, 1 };

	public static long josephProblem(long n, int k) {
		if (n == 1)
			return 0;
		if (k == 1)
			return n - 1;
		if (k > n)
			return (josephProblem(n - 1, k) + k) % n;
		long count = n / k;
		long result = josephProblem(n - count, k);
		result -= n % k;
		if (result < 0)
			result += n;
		else
			result += result / (k - 1);
		return result;
	}

	public static boolean isValidCell(int row, int column, int rowCount,
			int columnCount) {
		return row >= 0 && row < rowCount && column >= 0
				&& column < columnCount;
	}

	public static List<Integer> getPath(int[] last, int destination) {
		List<Integer> path = new ArrayList<Integer>();
		while (destination != -1) {
			path.add(destination);
			destination = last[destination];
		}
		inPlaceReverse(path);
		return path;
	}

	private static void inPlaceReverse(List<Integer> list) {
		for (int i = 0, j = list.size() - 1; i < j; i++, j--)
			swap(list, i, j);
	}

	private static void swap(List<Integer> list, int first, int second) {
		if (first == second)
			return;
		int temp = list.get(first);
		list.set(first, list.get(second));
		list.set(second, temp);
	}

	public static List<Integer> getPath(int[][] lastIndex,
			int[][] lastPathNumber, int destination, int pathNumber) {
		List<Integer> path = new ArrayList<Integer>();
		while (destination != -1 || pathNumber != 0) {
			path.add(destination);
			int nextDestination = lastIndex[destination][pathNumber];
			pathNumber = lastPathNumber[destination][pathNumber];
			destination = nextDestination;
		}
		inPlaceReverse(path);
		return path;
	}

	public static long maximalRectangleSum(long[][] array) {
		int n = array.length;
		int m = array[0].length;
		long[][] partialSums = new long[n + 1][m + 1];
		for (int i = 0; i < n; i++) {
			long rowSum = 0;
			for (int j = 0; j < m; j++) {
				rowSum += array[i][j];
				partialSums[i + 1][j + 1] = partialSums[i][j + 1] + rowSum;
			}
		}
		long result = Long.MIN_VALUE;
		for (int i = 0; i < m; i++) {
			for (int j = i; j < m; j++) {
				long minPartialSum = 0;
				for (int k = 1; k <= n; k++) {
					long current = partialSums[k][j + 1] - partialSums[k][i];
					result = Math.max(result, current - minPartialSum);
					minPartialSum = Math.min(minPartialSum, current);
				}
			}
		}
		return result;
	}

	public static int parseIP(String ip) {
		String[] components = ip.split("[.]");
		int result = 0;
		for (int i = 0; i < 4; i++)
			result += (1 << (24 - 8 * i)) * Integer.parseInt(components[i]);
		return result;
	}

	public static String buildIP(int mask) {
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < 4; i++) {
			if (i != 0)
				result.append('.');
			result.append(mask >> (24 - 8 * i) & 255);
		}
		return result.toString();
	}

	public static long binarySearch(long from, long to,
			Function<Long, Boolean> function) {
		while (from < to) {
			long argument = from + (to - from) / 2;
			if (function.value(argument))
				to = argument;
			else
				from = argument + 1;
		}
		return from;
	}

	public static <T> boolean equals(T first, T second) {
		return first == null && second == null || first != null
				&& first.equals(second);
	}

	public static boolean isVowel(char ch) {
		ch = Character.toUpperCase(ch);
		return ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'
				|| ch == 'Y';
	}

	public static boolean isStrictVowel(char ch) {
		ch = Character.toUpperCase(ch);
		return ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U';
	}

	public static String convertToRoman(int number) {
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < ROMAN_TOKENS.length; i++) {
			while (number >= ROMAN_VALUES[i]) {
				number -= ROMAN_VALUES[i];
				result.append(ROMAN_TOKENS[i]);
			}
		}
		return result.toString();
	}

	public static int convertFromRoman(String number) {
		int result = 0;
		for (int i = 0; i < ROMAN_TOKENS.length; i++) {
			while (number.startsWith(ROMAN_TOKENS[i])) {
				number = number.substring(ROMAN_TOKENS[i].length());
				result += ROMAN_VALUES[i];
			}
		}
		return result;
	}

	public static int distance(int x1, int y1, int x2, int y2) {
		int dx = x1 - x2;
		int dy = y1 - y2;
		return dx * dx + dy * dy;
	}

	public static <T extends Comparable<T>> T min(T first, T second) {
		if (first.compareTo(second) <= 0)
			return first;
		return second;
	}

	public static <T extends Comparable<T>> T max(T first, T second) {
		if (first.compareTo(second) <= 0)
			return second;
		return first;
	}

	public static void decreaseByOne(int[]... arrays) {
		for (int[] array : arrays) {
			for (int i = 0; i < array.length; i++)
				array[i]--;
		}
	}

	public static int[] getIntArray(String s) {
		String[] tokens = s.split(" ");
		int[] result = new int[tokens.length];
		for (int i = 0; i < result.length; i++)
			result[i] = Integer.parseInt(tokens[i]);
		return result;
	}
}

class IntegerUtils {
	public static long gcd(long a, long b) {
		a = Math.abs(a);
		b = Math.abs(b);
		while (b != 0) {
			long temp = a % b;
			a = b;
			b = temp;
		}
		return a;
	}

	public static int gcd(int a, int b) {
		a = Math.abs(a);
		b = Math.abs(b);
		while (b != 0) {
			int temp = a % b;
			a = b;
			b = temp;
		}
		return a;
	}

	public static int[] generatePrimes(int upTo) {
		int[] isPrime = generateBitPrimalityTable(upTo);
		List<Integer> primes = new ArrayList<Integer>();
		for (int i = 0; i < upTo; i++) {
			if ((isPrime[i >> 5] >>> (i & 31) & 1) == 1)
				primes.add(i);
		}
		int[] array = new int[primes.size()];
		for (int i = 0; i < array.length; i++)
			array[i] = primes.get(i);
		return array;
	}

	public static boolean[] generatePrimalityTable(int upTo) {
		boolean[] isPrime = new boolean[upTo];
		if (upTo < 2)
			return isPrime;
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for (int i = 2; i * i < upTo; i++) {
			if (isPrime[i]) {
				for (int j = i * i; j < upTo; j += i)
					isPrime[j] = false;
			}
		}
		return isPrime;
	}

	public static int[] generateBitPrimalityTable(int upTo) {
		int[] isPrime = new int[(upTo + 31) >> 5];
		if (upTo < 2)
			return isPrime;
		Arrays.fill(isPrime, -1);
		isPrime[0] &= -4;
		for (int i = 2; i * i < upTo; i++) {
			if ((isPrime[i >> 5] >>> (i & 31) & 1) == 1) {
				for (int j = i * i; j < upTo; j += i)
					isPrime[j >> 5] &= -1 - (1 << (j & 31));
			}
		}
		return isPrime;
	}

	public static int[] generateDivisorTable(int upTo) {
		int[] divisor = new int[upTo];
		for (int i = 1; i < upTo; i++)
			divisor[i] = i;
		for (int i = 2; i * i < upTo; i++) {
			if (divisor[i] == i) {
				for (int j = i * i; j < upTo; j += i)
					divisor[j] = i;
			}
		}
		return divisor;
	}

	public static long powerInFactorial(long n, long p) {
		long result = 0;
		while (n != 0) {
			result += n /= p;
		}
		return result;
	}

	public static int sumDigits(CharSequence number) {
		int result = 0;
		for (int i = number.length() - 1; i >= 0; i--)
			result += digitValue(number.charAt(i));
		return result;
	}

	public static int digitValue(char digit) {
		if (Character.isDigit(digit))
			return digit - '0';
		if (Character.isUpperCase(digit))
			return digit + 10 - 'A';
		return digit + 10 - 'a';
	}

	public static int longCompare(long a, long b) {
		if (a < b)
			return -1;
		if (a > b)
			return 1;
		return 0;
	}

	public static long[][] generateBinomialCoefficients(int n) {
		long[][] result = new long[n + 1][n + 1];
		for (int i = 0; i <= n; i++) {
			result[i][0] = 1;
			for (int j = 1; j <= i; j++)
				result[i][j] = result[i - 1][j - 1] + result[i - 1][j];
		}
		return result;
	}

	public static long[][] generateBinomialCoefficients(int n, long module) {
		long[][] result = new long[n + 1][n + 1];
		if (module == 1)
			return result;
		for (int i = 0; i <= n; i++) {
			result[i][0] = 1;
			for (int j = 1; j <= i; j++) {
				result[i][j] = result[i - 1][j - 1] + result[i - 1][j];
				if (result[i][j] >= module)
					result[i][j] -= module;
			}
		}
		return result;
	}

	public static long[] generateBinomialRow(int n, long module) {
		long[] result = generateReverse(n + 1, module);
		result[0] = 1;
		for (int i = 1; i <= n; i++)
			result[i] = result[i - 1] * (n - i + 1) % module * result[i]
					% module;
		return result;
	}

	public static int[] representationInBase(long number, int base) {
		long basePower = base;
		int exponent = 1;
		while (number >= basePower) {
			basePower *= base;
			exponent++;
		}
		int[] representation = new int[exponent];
		for (int i = 0; i < exponent; i++) {
			basePower /= base;
			representation[i] = (int) (number / basePower);
			number %= basePower;
		}
		return representation;
	}

	public static int trueDivide(int a, int b) {
		return (a - trueMod(a, b)) / b;
	}

	public static long trueDivide(long a, long b) {
		return (a - trueMod(a, b)) / b;
	}

	public static int trueMod(int a, int b) {
		a %= b;
		a += b;
		a %= b;
		return a;
	}

	public static long trueMod(long a, long b) {
		a %= b;
		a += b;
		a %= b;
		return a;
	}

	public static long factorial(int n) {
		long result = 1;
		for (int i = 2; i <= n; i++)
			result *= i;
		return result;
	}

	public static long factorial(int n, long mod) {
		long result = 1;
		for (int i = 2; i <= n; i++)
			result = result * i % mod;
		return result % mod;
	}

	public static List<Pair<Long, Integer>> factorize(long number) {
		List<Pair<Long, Integer>> result = new ArrayList<Pair<Long, Integer>>();
		for (long i = 2; i * i <= number; i++) {
			if (number % i == 0) {
				int power = 0;
				do {
					power++;
					number /= i;
				} while (number % i == 0);
				result.add(Pair.makePair(i, power));
			}
		}
		if (number != 1)
			result.add(Pair.makePair(number, 1));
		return result;
	}

	public static List<Long> getDivisors(long number) {
		List<Pair<Long, Integer>> primeDivisors = factorize(number);
		return getDivisorsImpl(primeDivisors, 0, 1, new ArrayList<Long>());
	}

	private static List<Long> getDivisorsImpl(
			List<Pair<Long, Integer>> primeDivisors, int index, long current,
			List<Long> result) {
		if (index == primeDivisors.size()) {
			result.add(current);
			return result;
		}
		long p = primeDivisors.get(index).first;
		int power = primeDivisors.get(index).second;
		for (int i = 0; i <= power; i++) {
			getDivisorsImpl(primeDivisors, index + 1, current, result);
			current *= p;
		}
		return result;
	}

	public static long power(long base, long exponent) {
		if (exponent == 0)
			return 1;
		long result = power(base, exponent >> 1);
		result = result * result;
		if ((exponent & 1) != 0)
			result = result * base;
		return result;
	}

	public static long power(long base, long exponent, long mod) {
		if (base >= mod)
			base %= mod;
		if (exponent == 0)
			return 1 % mod;
		long result = power(base, exponent >> 1, mod);
		result = result * result % mod;
		if ((exponent & 1) != 0)
			result = result * base % mod;
		return result;
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	public static long[] generateFibonacci(long upTo) {
		int count = 0;
		long last = 0;
		long current = 1;
		while (current <= upTo) {
			long next = last + current;
			last = current;
			current = next;
			count++;
		}
		return generateFibonacci(count, -1);
	}

	public static long[] generateFibonacci(int count, long module) {
		long[] result = new long[count];
		if (module == -1) {
			if (count != 0)
				result[0] = 1;
			if (count > 1)
				result[1] = 1;
			for (int i = 2; i < count; i++)
				result[i] = result[i - 1] + result[i - 2];
		} else {
			if (count != 0)
				result[0] = 1 % module;
			if (count > 1)
				result[1] = 1 % module;
			for (int i = 2; i < count; i++)
				result[i] = (result[i - 1] + result[i - 2]) % module;
		}
		return result;
	}

	public static long[] generateHappy(int digits) {
		long[] happy = new long[(1 << (digits + 1)) - 2];
		happy[0] = 4;
		happy[1] = 7;
		int first = 0;
		int last = 2;
		for (int i = 2; i <= digits; i++) {
			for (int j = 0; j < last - first; j++) {
				happy[last + 2 * j] = 10 * happy[first + j] + 4;
				happy[last + 2 * j + 1] = 10 * happy[first + j] + 7;
			}
			int next = last + 2 * (last - first);
			first = last;
			last = next;
		}
		return happy;
	}

	public static long[] generateFactorial(int count, long module) {
		long[] result = new long[count];
		if (module == -1) {
			if (count != 0)
				result[0] = 1;
			for (int i = 1; i < count; i++)
				result[i] = result[i - 1] * i;
		} else {
			if (count != 0)
				result[0] = 1 % module;
			for (int i = 1; i < count; i++)
				result[i] = (result[i - 1] * i) % module;
		}
		return result;
	}

	public static long reverse(long number, long module) {
		return power(number, module - 2, module);
	}

	public static boolean isPrime(long number) {
		if (number < 2)
			return false;
		for (long i = 2; i * i <= number; i++) {
			if (number % i == 0)
				return false;
		}
		return true;
	}

	public static long[] generateReverse(int upTo, long module) {
		long[] result = new long[upTo];
		if (upTo > 1)
			result[1] = 1;
		for (int i = 2; i < upTo; i++)
			result[i] = (module - module / i * result[((int) (module % i))]
					% module)
					% module;
		return result;
	}

	public static long[] generateReverseFactorials(int upTo, long module) {
		long[] result = generateReverse(upTo, module);
		if (upTo > 0)
			result[0] = 1;
		for (int i = 1; i < upTo; i++)
			result[i] = result[i] * result[i - 1] % module;
		return result;
	}

	public static long[] generatePowers(long base, int count, long mod) {
		long[] result = new long[count];
		if (count != 0)
			result[0] = 1 % mod;
		for (int i = 1; i < count; i++)
			result[i] = result[i - 1] * base % mod;
		return result;
	}

	public static long nextPrime(long from) {
		if (from <= 2)
			return 2;
		from += 1 - (from & 1);
		while (!isPrime(from))
			from += 2;
		return from;
	}

	public static long binomialCoefficient(int n, int m, long mod) {
		if (m < 0 || m > n)
			return 0;
		if (2 * m > n)
			m = n - m;
		long result = 1;
		for (int i = n - m + 1; i <= n; i++)
			result = result * i % mod;
		return result
				* BigInteger.valueOf(factorial(m, mod))
						.modInverse(BigInteger.valueOf(mod)).longValue() % mod;
	}

	public static boolean isSquare(long number) {
		long sqrt = Math.round(Math.sqrt(number));
		return sqrt * sqrt == number;
	}

	public static long findCommon(long aRemainder, long aMod, long bRemainder,
			long bMod) {
		long modGCD = gcd(aMod, bMod);
		long gcdRemainder = aRemainder % modGCD;
		if (gcdRemainder != bRemainder % modGCD)
			return -1;
		aMod /= modGCD;
		aRemainder /= modGCD;
		bMod /= modGCD;
		bRemainder /= modGCD;
		long aReverse = BigInteger.valueOf(aMod)
				.modInverse(BigInteger.valueOf(bMod)).longValue();
		long bReverse = BigInteger.valueOf(bMod)
				.modInverse(BigInteger.valueOf(aMod)).longValue();
		long mod = aMod * bMod;
		return (bReverse * aRemainder % mod * bMod + aReverse * bRemainder
				% mod * aMod)
				% mod * modGCD + gcdRemainder;
	}

	public static long[] generatePowers(long base, long maxValue) {
		if (maxValue <= 0)
			return new long[0];
		int size = 1;
		long current = 1;
		while (maxValue / base >= current) {
			current *= base;
			size++;
		}
		return generatePowers(base, size, Long.MAX_VALUE);
	}
}

interface IntComparator extends Comparator<Integer> {
	public static final IntComparator DEFAULT = new IntComparator() {
		public int compare(Integer first, Integer second) {
			if (first < second)
				return -1;
			if (first > second)
				return 1;
			return 0;
		}
	};

	public static final IntComparator REVERSE = new IntComparator() {
		public int compare(Integer first, Integer second) {
			if (first < second)
				return 1;
			if (first > second)
				return -1;
			return 0;
		}
	};

	public int compare(Integer first, Integer second);
}

class BidirectionalGraph extends Graph {
	public int[] transposedEdge;

	public BidirectionalGraph(int vertexCount) {
		this(vertexCount, vertexCount);
	}

	public BidirectionalGraph(int vertexCount, int edgeCapacity) {
		super(vertexCount, 2 * edgeCapacity);
		transposedEdge = new int[2 * edgeCapacity];
	}

	public static BidirectionalGraph createGraph(int vertexCount, int[] from,
			int[] to) {
		BidirectionalGraph graph = new BidirectionalGraph(vertexCount,
				from.length);
		for (int i = 0; i < from.length; i++)
			graph.addSimpleEdge(from[i], to[i]);
		return graph;
	}

	public static BidirectionalGraph createWeightedGraph(int vertexCount,
			int[] from, int[] to, long[] weight) {
		BidirectionalGraph graph = new BidirectionalGraph(vertexCount,
				from.length);
		for (int i = 0; i < from.length; i++)
			graph.addWeightedEdge(from[i], to[i], weight[i]);
		return graph;
	}

	public static BidirectionalGraph createFlowGraph(int vertexCount,
			int[] from, int[] to, long[] capacity) {
		BidirectionalGraph graph = new BidirectionalGraph(vertexCount,
				from.length * 2);
		for (int i = 0; i < from.length; i++)
			graph.addFlowEdge(from[i], to[i], capacity[i]);
		return graph;
	}

	public static BidirectionalGraph createFlowWeightedGraph(int vertexCount,
			int[] from, int[] to, long[] weight, long[] capacity) {
		BidirectionalGraph graph = new BidirectionalGraph(vertexCount,
				from.length * 2);
		for (int i = 0; i < from.length; i++)
			graph.addFlowWeightedEdge(from[i], to[i], weight[i], capacity[i]);
		return graph;
	}

	@Override
	public int addEdge(int fromID, int toID, long weight, long capacity,
			int reverseEdge) {
		int lastEdgeCount = edgeCount;
		super.addEdge(fromID, toID, weight, capacity, reverseEdge);
		super.addEdge(toID, fromID, weight, capacity, reverseEdge == -1 ? -1
				: reverseEdge + 1);
		this.transposedEdge[lastEdgeCount] = lastEdgeCount + 1;
		this.transposedEdge[lastEdgeCount + 1] = lastEdgeCount;
		return lastEdgeCount;
	}

	@Override
	protected int entriesPerEdge() {
		return 2;
	}

	@Override
	public final int transposed(int id) {
		return transposedEdge[id];
	}

	@Override
	protected void ensureEdgeCapacity(int size) {
		if (size > edgeCapacity()) {
			super.ensureEdgeCapacity(size);
			transposedEdge = resize(transposedEdge, edgeCapacity());
		}
	}
}

class Pair<U, V> implements Comparable<Pair<U, V>> {
	public final U first;
	public final V second;

	public static <U, V> Pair<U, V> makePair(U first, V second) {
		return new Pair<U, V>(first, second);
	}

	private Pair(U first, V second) {
		this.first = first;
		this.second = second;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Pair pair = (Pair) o;

		return !(first != null ? !first.equals(pair.first) : pair.first != null)
				&& !(second != null ? !second.equals(pair.second)
						: pair.second != null);

	}

	@Override
	public int hashCode() {
		int result = first != null ? first.hashCode() : 0;
		result = 31 * result + (second != null ? second.hashCode() : 0);
		return result;
	}

	public Pair<V, U> swap() {
		return makePair(second, first);
	}

	@Override
	public String toString() {
		return "(" + first + "," + second + ")";
	}

	@SuppressWarnings({ "unchecked" })
	public int compareTo(Pair<U, V> o) {
		int value = ((Comparable<U>) first).compareTo(o.first);
		if (value != 0)
			return value;
		return ((Comparable<V>) second).compareTo(o.second);
	}
}

interface Edge {
	public int getSource();

	public int getDestination();

	public long getWeight();

	public long getCapacity();

	public long getFlow();

	public void pushFlow(long flow);

	public boolean getFlag(int bit);

	public void setFlag(int bit);

	public void removeFlag(int bit);

	public int getTransposedID();

	public Edge getTransposedEdge();

	public int getReverseID();

	public Edge getReverseEdge();

	public int getID();

	public void remove();

	public void restore();
}

interface Function<A, V> {
	public abstract V value(A argument);
}

import java.math.BigInteger;
import java.util.Scanner;

public class FoxDividingCheese {

    public static int gcd(int a,int b) {
        return (BigInteger.valueOf(b).gcd(BigInteger.valueOf(a))).intValue();
    }

    public static int steps235(int x) {
        if (x == 1) return 0;
        int sprev;
        if (x % 2 == 0) sprev = steps235(x/2);
        else if (x % 3 == 0) sprev = steps235(x/3);
        else if (x % 5 == 0) sprev = steps235(x/5);
        else return -1;
        if (sprev == -1) return -1;
        return sprev+1;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt();
        in.close();
        int g = gcd(a,b);
        int ag = a/g, bg = b/g;
        int as = steps235(ag), bs = steps235(bg);
        if (as == -1 || bs == -1) {
            System.out.println(-1);
            return;
        }
        System.out.println(as+bs);
    }

}

import java.util.Scanner;
public class Main371B
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=gcd(a,b);
    int d=(a/c);
    int e=(b/c);
    int ans=0;
    while(d%2==0)
    {
      d/=2;
      ans++;
    }
    while(d%3==0)
    {
      d/=3;
      ans++;
    }
    while(d%5==0)
    {
      d/=5;
      ans++;
    }
    if(d!=1)
      System.out.println(-1);
    else
    {
      while(e!=1)
      {
        if(e%2==0)
        {
          e/=2;
          ans++;
        }
        else if(e%3==0)
        {
          e/=3;
          ans++;
        }
        else if(e%5==0)
        {
          e/=5;
          ans++;
        }
        else
          break;
      }
      if(e!=1)
        System.out.println(-1);
      else
        System.out.println(ans);
    }
  }
  public static int gcd(int a,int b)
  {
    if(a==0) return b;
    else return gcd(b%a,a);
  }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {

        public void solve(int testNumber, InputReader input, PrintWriter out) {
            int x = input.nextInt();
            int y = input.nextInt();
            //0->2  1->3    2->5
            int [] n1 = new int [3];
            int [] n2 = new int [3];

            while(true){
                if (x %2 == 0){
                    n1[0]++;
                    x/=2;
                }else if (x%3 == 0){
                    n1[1]++;
                    x/=3;
                }else if (x%5 == 0){
                    n1[2]++;
                    x/=5;
                }else {
                    break;
                }
            }
             while(true){
                if (y %2 == 0){
                    n2[0]++;
                    y/=2;
                }else if (y%3 == 0){
                    n2[1]++;
                    y/=3;
                }else if (y%5 == 0){
                    n2[2]++;
                    y/=5;
                }else {
                    break;
                }
            }

             out.println((x != y)? -1:(Math.abs(n1[0] - n2[0]) + Math.abs(n1[1] - n2[1]) + Math.abs(n1[2] - n2[2])));

        }

    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

import java.io.*;
import java.util.*;

public class B
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        if (a == b)
        {
            out.print(0);
            out.close();
            System.exit(0);
        }
        int[] af = new int[3];
        int[] bf = new int[3];
        int t = a;
        while (t%2 == 0)
        {
            af[0]++;
            t /= 2;
        }
        while (t%3 == 0)
        {
            af[1]++;
            t /= 3;
        }
        while (t%5 == 0)
        {
            af[2]++;
            t /= 5;
        }
        int t2 = t;
        t = b;
        while (t%2 == 0)
        {
            bf[0]++;
            t /= 2;
        }
        while (t%3 == 0)
        {
            bf[1]++;
            t /= 3;
        }
        while (t%5 == 0)
        {
            bf[2]++;
            t /= 5;
        }
        if (t != t2)
        {
            out.print(-1);
            out.close();
            System.exit(0);
        }
        int count = 0;
        for (int i = 0; i < 3; i++)
        {
            count += Math.abs(af[i] - bf[i]);
        }
        out.print(count);
        out.close();
        System.exit(0);
    }
}

import java.util.Scanner;

public class main {
    static int a, b;
    static int ans;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        a = scanner.nextInt();
        b = scanner.nextInt();

        findPowers(2);
        findPowers(3);
        findPowers(5);
        System.out.println((a == b? ans : -1));

    }

    static void findPowers(int base) {
        int counterA = 0;
        int counterB = 0;

        while (a % base == 0) {
            a /= base;
            counterA++;
        }

        while (b % base == 0) {
            b /= base;
            counterB++;
        }

        ans += Math.abs(counterA - counterB);
    }

}

import java.util.*;
import java.io.*;
public class Main {
      static class pair implements Comparable<pair>{
        int x;
        int y;
        public pair(int x, int y){
            this.x=x;
            this.y=y;
        }
        public int compareTo(pair p){
            return (x-p.x==0)?y-p.y:x-p.x;
        }}
        static int n; static int m;
        static int arr[];
        static int dp[][][][];
        public static int solve(int n, int m, int c1, int c2,int k1, int k2){
            if(n==m) return 0;
            if(n<1||m<1) return Integer.MAX_VALUE;
            if(dp[c1][c2][k1][k2]!=-1) return dp[c1][c2][k1][k2];
            int ans = Integer.MAX_VALUE;
            for(int i=0; i<4; i++){
               loop: for(int j=0; j<4; j++){
                    if(n%arr[i]==0&&m%arr[j]==0){
                        if(i!=0||j!=0) {
                        ans = Math.min(ans,(i==0||j==0)?(i==0)?1+solve(n/arr[i],m/arr[j],c1,c2+1,i,j):1+solve(n/arr[i],m/arr[j],c1+1,c2,i,j):2+solve(n/arr[i],m/arr[j],c1+1,c2+1,i,j));}
                    }
                }
            }
            return ans;
        }
  public static void main(String[] args) throws IOException,InterruptedException{
	BufferedReader	 br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(System.out);
     	// String s = br.readLine();
        // char[] arr=s.toCharArray();
        // ArrayList<Integer> arrl = new ArrayList<Integer>();
        // TreeSet<Integer> ts1 = new TreeSet<Integer>();
        // HashSet<Integer> h = new HashSet<Integer>();
        // HashMap<Integer, Integer> map= new HashMap<>();
        // PriorityQueue<String> pQueue = new PriorityQueue<String>();
        // LinkedList<String> object = new LinkedList<String>();
        // StringBuilder str = new StringBuilder();
 	    StringTokenizer   st = new StringTokenizer(br.readLine());
 	   	  n = Integer.parseInt(st.nextToken());
 	   	  m = Integer.parseInt(st.nextToken());
 	   	  arr = new int[]{2,3,5};
 	   	  int[]a = new int[3];
 	   	  int[]b = new int[3];
 	   	  for(int i=0; i<3; i++){
 	   	      while(n%arr[i]==0){
 	   	          n/=arr[i];
 	   	          a[i]++;
 	   	      }
 	   	      while(m%arr[i]==0){
 	   	          m/=arr[i];
 	   	          b[i]++;
 	   	      }
 	   	  }
 	   	  out.println((n==m)?Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1])+Math.abs(a[2]-b[2]):-1);
          out.flush();
	}

}

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
  private static BufferedReader br;
  private static StringTokenizer st;
  private static PrintWriter pw;

  public static void main(String[] args) throws IOException {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    //int qq = 1;
    int qq = Integer.MAX_VALUE;
    //int qq = readInt();
    for(int casenum = 1; casenum <= qq; casenum++)  {
      int a = readInt();
      int b = readInt();
      Map<State, Integer> map = new HashMap<State, Integer>();
      LinkedList<State> q = new LinkedList<State>();
      q.add(new State(a,b));
      map.put(new State(a,b), 0);
      while(!q.isEmpty()) {
        State curr = q.removeFirst();
        if(curr.a%2==0) {
          State next = new State(curr.a * 1 / 2, curr.b);
          if(!map.containsKey(next)) {
            map.put(next, 1 + map.get(curr));
            q.add(next);
          }
        }
        if(curr.a%3==0) {
          State next = new State(curr.a * 1 / 3, curr.b);
          if(!map.containsKey(next)) {
            map.put(next, 1 + map.get(curr));
            q.add(next);
          }
        }
        if(curr.a%5==0) {
          State next = new State(curr.a * 1 / 5, curr.b);
          if(!map.containsKey(next)) {
            map.put(next, 1 + map.get(curr));
            q.add(next);
          }
        }
        if(curr.b%2==0) {
          State next = new State(curr.a, curr.b * 1 / 2);
          if(!map.containsKey(next)) {
            map.put(next, 1 + map.get(curr));
            q.add(next);
          }
        }
        if(curr.b%3==0) {
          State next = new State(curr.a, curr.b * 1 / 3);
          if(!map.containsKey(next)) {
            map.put(next, 1 + map.get(curr));
            q.add(next);
          }
        }
        if(curr.b%5==0) {
          State next = new State(curr.a, curr.b * 1 / 5);
          if(!map.containsKey(next)) {
            map.put(next, 1 + map.get(curr));
            q.add(next);
          }
        }
      }
      int ret = Integer.MAX_VALUE;
      for(State out: map.keySet()) {
        if(out.a == out.b) {
          ret = Math.min(ret, map.get(out));
        }
      }
      if(ret == Integer.MAX_VALUE) {
        ret = -1;
      }
      pw.println(ret);
    }
    pw.close();
  }

  static class State {
    public int a,b;

    public State(int a, int b) {
      super();
      this.a = a;
      this.b = b;
    }

    @Override
    public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + a;
      result = prime * result + b;
      return result;
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj)
        return true;
      if (obj == null)
        return false;
      if (getClass() != obj.getClass())
        return false;
      State other = (State) obj;
      if (a != other.a)
        return false;
      if (b != other.b)
        return false;
      return true;
    }

  }

  private static void exitImmediately() {
    pw.close();
    System.exit(0);
  }

  private static long readLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  private static double readDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  private static int readInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  private static String nextToken() throws IOException  {
    while(st == null || !st.hasMoreTokens())  {
      if(!br.ready()) {
        exitImmediately();
      }
      st = new StringTokenizer(br.readLine().trim());
    }
    return st.nextToken();
  }
}

import java.util.*;

public class B {
	private static final int [] DIVISORS = {2, 3, 5};
	private static int [] factors(int n){
		final int [] res = new int[DIVISORS.length + 1];
		for (int i = 0; i < DIVISORS.length; ++i){
			while (n%DIVISORS[i] == 0){
				n /= DIVISORS[i];
				res[i]++;
			}
		}
		res[DIVISORS.length] = n;
		return res;
	}
	private static int solve(int a, int b){
		final int [] af = factors(a);
		final int [] bf = factors(b);
		if (af[DIVISORS.length] != bf[DIVISORS.length]){
			return -1;
		}
		int res = 0;
		for (int i = 0; i < DIVISORS.length; ++i){
			res += Math.abs(af[i] - bf[i]);
		}
		return res;
	}
	public static void main(String [] args){
		final Scanner s = new Scanner(System.in);
		final int a = s.nextInt();
		final int b = s.nextInt();
		System.out.println(solve(a, b));
		s.close();
	}
}

import java.util.*;
import javafx.util.*;

public class Master {

    public static Scanner in = new Scanner(System.in);

    public static ArrayList<Integer> fact(int n) {
        ArrayList<Integer> st = new ArrayList<Integer>();
        while (n % 2 == 0 || n % 3 == 0 || n % 5 == 0) {
            if (n % 2 == 0) {
                st.add(2);
                n /= 2;
            } else if (n % 3 == 0) {
                st.add(3);
                n /= 3;
            } else if (n % 5 == 0) {
                st.add(5);
                n /= 5;
            }
        }
        st.add(n);
        return st;
    }

    public static void main(String[] args) {
        int a = in.nextInt();
        int b = in.nextInt();
        ArrayList<Integer> st1 = fact(a);
        ArrayList<Integer> st2 = fact(b);
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        HashMap<Integer, Integer> map1 = new HashMap<Integer, Integer>();
        HashMap<Integer, Integer> map2 = new HashMap<Integer, Integer>();
        for (int key : st1) {
            if (map1.containsKey(key)) {
                map1.put(key, map1.get(key) + 1);
            } else {
                map1.put(key, 1);
            }
        }
        for (int key : st2) {
            if (map2.containsKey(key)) {
                map2.put(key, map2.get(key) + 1);
            } else {
                map2.put(key, 1);
            }
        }

        Iterator<Integer> ptr = map1.keySet().iterator();

        long mult = 1;
        while (ptr.hasNext()) {
            int key = ptr.next();
            if (map1.containsKey(key) && map2.containsKey(key)) {
                int min = Math.min(map1.get(key), map2.get(key));
                map.put(key, min);
                mult *= (Math.pow(key, min));
            }
        }
        a /= mult;
        b /= mult;

        boolean flg1 = true;
        boolean flg2 = true;
        st1 = fact(a);
        st2 = fact(b);
        for (int val : st1) {
            if (val != 2 && val != 3 && val != 5 && val != 1) {

                flg1 = false;
                break;
            }
        }
        for (int val : st2) {
            if (val != 2 && val != 3 && val != 5 && val != 1) {
                flg2 = false;
                break;
            }
        }
        if (flg1 && flg2) {
            int ans = 0;
            for (int val : st1) {
                if (val != 1) {
                    ans++;
                }
            }
            for (int val : st2) {
                if (val != 1) {
                    ans++;
                }
            }
            System.out.println(ans);
        } else {

            System.out.println("-1");
        }
    }

}

//package solve;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Solve {

    private static Map<Integer, Integer> fillMapAdd(int value){
        Map<Integer, Integer> map = new HashMap<>();

        return map;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int array[] = new int[3];
        int a = sc.nextInt();
        boolean bool = true;
        while(bool){
            bool = false;
            if(a % 2 == 0){
                array[0]++;
                a /= 2;
                bool = true;
            }
            if(a % 3 == 0){
                array[1]++;
                a /= 3;
                bool = true;
            }
            if(a % 5 == 0){
                array[2]++;
                a /= 5;
                bool = true;
            }
        }
        int b = sc.nextInt();
        bool = true;
        while(bool){
            bool = false;
            if(b % 2 == 0){
                array[0]--;
                b /= 2;
                bool = true;
            }
            if(b % 3 == 0){
                array[1]--;
                b /= 3;
                bool = true;
            }
            if(b % 5 == 0){
                array[2]--;
                b /= 5;
                bool = true;
            }
        }
        if(a != b){
            System.out.println("-1");
        }else{
            System.out.println(Math.abs(array[0]) + Math.abs(array[1]) + Math.abs(array[2]));
        }
        sc.close();
    }

}

import java.util.Scanner;
public class cheese371B
{
    public int hcf(int a,int b)
    {
        if(b==0)
            return a;
        return hcf(b,a%b);
    }
    public static void main(String args[])
    {
        Scanner s =new Scanner(System.in);
        cheese371B cb=new cheese371B();
        int a,b;
        a=s.nextInt();
        b=s.nextInt();
        int ans=0;
        int ansa=0,ansb=0;
        //hcf
        int tmp = cb.hcf(a,b);
        int tmpa,tmpb;
        tmpa=a/tmp;
        tmpb=b/tmp;
        if(tmpa!=1)
        {
            while(tmpa%2==0)
            {
                ++ansa;
                tmpa=tmpa/2;
            }
        }
        if(tmpa!=1)
        {
            while(tmpa%3==0)
            {
                ++ansa;
                tmpa=tmpa/3;
            }
        }
        if(tmpa!=1)
        {
            while(tmpa%5==0)
            {
                ++ansa;
                tmpa=tmpa/5;
            }
        }
        if(tmpa!=1)
        {
            ans=-1;
        }
        if(tmpb!=1)
        {
            while(tmpb%2==0)
            {
                ++ansb;
                tmpb=tmpb/2;
            }
        }
        if(tmpb!=1)
        {
            while(tmpb%3==0)
            {
                ++ansb;
                tmpb=tmpb/3;
            }
        }
        if(tmpb!=1)
        {
            while(tmpb%5==0)
            {
                ++ansb;
                tmpb=tmpb/5;
            }
        }
        if(tmpb!=1)
        {
            ans=-1;
        }
        if(ans!=-1)
        {
            ans=ansa+ansb;
        }
        System.out.println(ans);
    }
}

import java.util.Scanner;

public class _371B {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		scanner.close();

		if (a == b) {
			System.out.print(0);
			return;
		}
		int[] del = {2, 3, 5};
		int[] del_a = new int[del.length];
		int[] del_b = new int[del.length];

		for (int i = 0; i < del.length; i++) {
			while (a % del[i] == 0) {
				del_a[i]++;
				a /= del[i];
			}

			while (b % del[i] == 0) {
				del_b[i]++;
				b /= del[i];
			}
		}

		if (a != b) {
			System.out.print(-1);
			return;
		}
		int sum = 0;
		for (int i = 0; i < del.length; i++) {
			sum += Math.abs(del_b[i] - del_a[i]);
		}
		System.out.print(sum);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

public class Main {

    static int GCD(int x, int y) {
        if (y == 0) {
            return x;
        } else {
            return GCD(y, x % y);
        }
    }

    public static void main(String[] args) throws IOException {
//        System.out.println(GCD(6, 18));
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        String line = reader.readLine();
        long x = System.currentTimeMillis();
        args = line.split(" ");

        LinkedList solutionsP = new LinkedList();
        LinkedList solutionsC = new LinkedList();

        solutionsP.add(new Solution(Integer.parseInt(args[0]), Integer.parseInt(args[1])));

        int gcd = GCD(((Solution)solutionsP.get(0)).x, ((Solution)solutionsP.get(0)).y);
        ((Solution)solutionsP.get(0)).x = ((Solution)solutionsP.get(0)).x / gcd;
        ((Solution)solutionsP.get(0)).y = ((Solution)solutionsP.get(0)).y / gcd;

        int[] ops = new int[]{5, 3, 2};
        int depth = 0;
        boolean isEqual = false;

        while (!solutionsP.isEmpty()) {
            Solution s = (Solution) solutionsP.poll();
            if (s.x == s.y) {
                isEqual = true;
                break;
            }

            if (s.x > s.y) {
                for (int i = 0; i < 3; i++) {
                    if (s.x % ops[i] == 0) {
                        solutionsC.add(new Solution(s.x / ops[i], s.y));
                    }
                }
            }

            if (s.y > s.x) {
                for (int i = 0; i < 3; i++) {
                    if (s.y % ops[i] == 0) {
                        solutionsC.add(new Solution(s.x, s.y / ops[i]));
                    }
                }
            }

            if (solutionsP.isEmpty()) {
                LinkedList temp = solutionsP;
                solutionsP = solutionsC;
                solutionsC = temp;
                solutionsC.clear();
                depth++;
            }

        }
        if (isEqual) {
            System.out.println(depth);
        } else {
            System.out.println("-1");
        }
        //System.out.println((System.currentTimeMillis() - x) / 1000.0);
    }

    private static final class Solution {

        public int x;
        public int y;

        Solution(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
}
// 509607936 306110016

import java.util.Scanner;

/**
 * Created by Michael on 9/10/14.
 */
public class B_218 {
    public static void main(String...bob) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int gcd = gcd(a, b);
        if(a == b){
            System.out.println(0);
        }
        else {
            int[] divide = {2, 3, 5};
            a /= gcd;
            b /= gcd;
            int count = 0;
            for (int i = 2; i >= 0; i--) {
                while (a % divide[i] == 0) {
                    count++;
                    a /= divide[i];
                }
                while (b % divide[i] == 0) {
                    count++;
                    b /= divide[i];
                }
            }
            if(a == b)
                System.out.println(count);
            else
                System.out.println(-1);
        }

    }
    public static int gcd(int a, int b){
        if(a == 0)
            return b;
        return gcd(b % a, a);
    }
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();
        int[] aa, bb;
        aa = new int[6];
        bb = new int[6];
        int[] primes = {2, 3, 5};
        for(int i: primes) {
            while(a%i == 0) { a /= i; aa[i]++;}
            while(b%i == 0) { b /= i; bb[i]++;}
        }
        if(a != b) System.out.println(-1);
        else System.out.println(Math.abs(aa[2] - bb[2]) + Math.abs(aa[3] - bb[3]) + Math.abs(aa[5] - bb[5]));
    }
}

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
public class TaskA {
       public static void main(String[] args) throws IOException{
    	   FastIn in = new FastIn(System.in);
    	   int a = in.readInt();
    	   int b = in.readInt();
    	   int minOps = 0;
    	   if(a==b);
    	   else{
    		     int a2=0,a3=0,a5=0;
    		     int b2=0,b3=0,b5=0;
    		     while(a%2==0){a/=2;a2++;}
    		     while(a%3==0){a/=3;a3++;}
    		     while(a%5==0){a/=5;a5++;}
    		     while(b%2==0){b/=2;b2++;}
    		     while(b%3==0){b/=3;b3++;}
    		     while(b%5==0){b/=5;b5++;}
    		     minOps+=Math.abs(a2-b2);
    		     minOps+=Math.abs(a3-b3);
    		     minOps+=Math.abs(a5-b5);
    		     if(a!=b){minOps=-1;}
    	   }
    	   System.out.println(minOps);
       }
}
class FastIn{
	private byte[] buffer;
	private InputStream stream;
	private int readChar;
	private int curChar;
	FastIn(InputStream in){
		this.stream = in;
		buffer = new byte[1024];
		readChar=0;
		curChar = -1;
	}
	private int read() throws IOException{
		if(curChar == -1 || curChar == 1024){
			 readChar = stream.read(buffer);
			 if(readChar == -1){return -1;}
			 curChar = 0;
		}
		return (int) buffer[curChar++];
	}
	public int readInt() throws IOException{
	       char c= (char) read();
	       while(isSpace(c)) c = (char) read();
	       int sign,value=0;
	       if(c=='-'){sign = -1;c='0';}
	       else{sign = 1;}
	       do{
	    	   value *= 10;
	    	   value += c-'0';
	       }while(!isSpace(c = (char) read()));
	       return sign*value;
	}
	public String readString() throws IOException{
		char c = (char) read();
		while(isSpace(c))c = (char) read();
		StringBuilder sb = new StringBuilder();
		do{
			sb.append(c);
		}while(!isSpace(c = (char) read()));
		return sb.toString();
	}
	public boolean isSpace(char c){
		int x = (int) c;
		return ((x==32||x== 10 )||(x== 9 ||x==13));
	}
	public void close() throws IOException{
		stream.close();
	}
}

import java.util.Scanner;

public class B371 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
int n = sc.nextInt();
int m=sc.nextInt();
int a[]=new int[3];
int b[]=new int[3];

a[0]=method(n,2);
a[1]=method(n,3);
a[2]=method(n,5);

b[0]=method(m,2);
b[1]=method(m,3);
b[2]=method(m,5);

if(n==m)
	System.out.println(0);
else if(method1(n,a)!=method1(m,b))
	System.out.println(-1);
else
	System.out.println(Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1])+Math.abs(a[2]-b[2]));

	}
static int method(int x, int y){
	int count=0;
	while(x%y==0){
		x=x/y;
		count++;
	}
	return count;

}
static int method1(int x, int[] y){

	return (int) (x/(Math.pow(2, y[0])*Math.pow(3, y[1])*Math.pow(5, y[2])));

}

}

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		if (a == b) {
			System.out.println(0);
		} else {
			int a2 = f(a, 2);
			int a3 = f(a, 3);
			int a5 = f(a, 5);
			int b2 = f(b, 2);
			int b3 = f(b, 3);
			int b5 = f(b, 5);
			int min2 = Math.min(a2, b2);
			int min3 = Math.min(a3, b3);
			int min5 = Math.min(a5, b5);
			int ans = 0;
			if(a2 < b2){
				for(int i = 0; i < b2 - a2; i++){
					b/=2;
					ans++;
				}
			}else{
				for(int i = 0; i < a2 - b2; i++){
					a/=2;
					ans++;
				}
			}
			if(a3 < b3){
				for(int i = 0; i < b3 - a3; i++){
					b/=3;
					ans++;
				}
			}else{
				for(int i = 0; i < a3 - b3; i++){
					a/=3;
					ans++;
				}
			}
			if(a5 < b5){
				for(int i = 0; i < b5 - a5; i++){
					b/=5;
					ans++;
				}
			}else{
				for(int i = 0; i < a5 - b5; i++){
					a/=5;
					ans++;
				}
			}
			if(a == b){
				System.out.println(ans);
			}else{
				System.out.println(-1);
			}

		}
	}

	private static int f(int a, int i) {
		int ans = 0;
		int temp = a;
		while(temp % i == 0){
			temp /= i;
			ans++;
		}
		return ans;
	}

}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();int m=sc.nextInt();
		int x=0,y=0,z=0;
		int p=0,q=0,r=0;
		while(n>=1&&n%2==0){
		    x++;n=n/2;
		}
		while(n>=1&&n%3==0){
		    y++;n=n/3;
		}
		while(n>=1&&n%5==0){
		    z++;n=n/5;
		}
		while(m>=1&&m%2==0){
		    p++;m=m/2;
		}
		while(m>=1&&m%3==0){
		    q++;m=m/3;
		}
		while(m>=1&&m%5==0){
		    r++;m=m/5;
		}
		if(n==m){
		    int xk=Math.abs(x-p)+Math.abs(y-q)+Math.abs(z-r);
		    System.out.println(xk);
		}
		else System.out.println(-1);
	}
}

import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Solution implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");
    static String[] args;

    public static void main(String[] args) {
        Solution.args = args;
        new Thread(null, new Solution(), "", 256 * (1L << 20)).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            if (System.getProperty("ONLINE_JUDGE") != null) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                String file = "input.txt";
                if (args.length > 0) {
                    file = args[0];
                }
                in = new BufferedReader(new FileReader(file));
                out = new PrintWriter("output.txt");
            }
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    // solution
    int[] pieces(int x) {
        int[] result = new int[3];
        if ((x & 1) == 0)
            result[0] = x>>1;
        if (x % 3 == 0)
            result[1] = x/3;
        if (x % 5 == 0)
            result[2] = x/5;
        return result;
    }

    int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a%b);
    }

    void solve() throws IOException {
        int a = readInt(), b = readInt();
        /* if (a == b) { */
        /*     System.out.println(0); */
        /*     return; */
        /* } */
        int g = gcd(a, b);
        int da = a/g;
        int[] dd = new int[3];

        while (da%5 ==0) {
            dd[2]++;
            da/=5;
        }
        while (da%3 ==0) {
            dd[2]++;
            da/=3;
        }
        while (da % 2 == 0) {
            dd[0]++;
            da/=2;
        }
        if (a == g) da = 1;
        if (da != 1) {
            System.out.println("-1");
            return;
        }
        int db = b/g;
        while (db%5 ==0) {
            dd[2]++;
            db/=5;
        }
        while (db%3 ==0) {
            dd[2]++;
            db/=3;
        }
        while (db % 2 == 0) {
            dd[0]++;
            db/=2;
        }
        if (b == g) db = 1;
        if (db != 1) {
            System.out.println("-1");
            return;
        }
        System.out.println(dd[0]+dd[1]+dd[2]);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int a = in.nextInt();
        int b = in.nextInt();
        System.out.println(cf(a,b));
    }

    private static int cf(int a, int b) {
        int a2 = 0, a3 = 0, a5 = 0, b2 = 0, b3 = 0, b5 = 0;
        while (a % 2 == 0) {
            a/=2;a2++;
        }
        while (a % 3 == 0) {
            a/=3;a3++;
        }
        while (a % 5 == 0) {
            a/=5;a5++;
        }
        while (b % 2 == 0) {
            b/=2;b2++;
        }
        while (b % 3 == 0) {
            b/=3;b3++;
        }
        while (b % 5 == 0) {
            b/=5;b5++;
        }
        if (a!=b)return -1;
        return Math.abs(a2 - b2) + Math.abs(a3 - b3) + Math.abs(a5 - b5);
    }
    private static long pow2(int i) {
        long ans =1;
        long two = 2;
        while (i > 0) {
            if (i%2==1)ans*=two;
            two *= two;
            i /= 2;
        }
        return ans;
    }

    private static void printArray(int[] arr, int startPosition, int toPosition) {
        for (int i = startPosition; i <= toPosition; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
}

		import java.io.*;
		import java.util.*;
		public class Sample {
		    static int MAX = (int)1e6+1;
		    static int MOD=(int)1e9+7;
		    static int countt = 0;
			public static void main(String[] args) throws Exception{
				// TODO Auto-generated method stub
				//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
				Scanner input  = new Scanner(System.in);
				int a = input.nextInt();
				int b = input.nextInt();
				int count1[] = new int[3];
				int count2[] = new int[3];
				while(a%2 == 0) {a/=2;count1[0]++;}
				while(a%3 == 0) {a/=3;count1[1]++;}
				while(a%5 == 0) {a/=5;count1[2]++;}
				while(b%2 == 0) {b/=2;count2[0]++;}
				while(b%3 == 0) {b/=3;count2[1]++;}
				while(b%5 == 0) {b/=5;count2[2]++;}
				if(a == b) {
					int a2 = Math.min(count1[0], count2[0]);
					count1[0]-=a2;count2[0]-=a2;
					int a3 = Math.min(count1[1], count2[1]);
					count2[1]-=a3;count2[1]-=a3;
					int a5 = Math.min(count1[2], count2[2]);
					count1[2]-=a5;count2[2]-=a5;
					int count =0;
					for(int i =0;i<3;i++) {count+=count1[i];count+=count2[i];}
					System.out.println(count);
				}else System.out.println(-1);
			}
		}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class B_FoxDivideCheese {
	static int n;
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
		String[] in = scan.readLine().split(" ");

		int a = parse(in[0]), b = parse(in[1]);

		int gcd = gcd(Math.max(a, b), Math.min(a, b));

		int pt1 = reduce(a / gcd);
		int pt2 = reduce(b / gcd);

		if(pt1 == Integer.MAX_VALUE || pt2 == Integer.MAX_VALUE)
			System.out.println("-1");
		else
		{
			System.out.println(pt1 + pt2);
		}
	}

	public static int reduce(int num)
	{
		int[] eat = {2, 3, 5};
		int count = 0;

		for(int i = 0; i < 3; i++)
		{
			while(num > 1 && num % eat[i] == 0)
			{
				num /= eat[i];
				count++;
			}
		}

		if(num > 1)
			return Integer.MAX_VALUE;
		return count;

	}

	public static int gcd(int a, int b)
	{
		if(b == 0 || a == b)
			return a;

		return gcd(b, a%b);
	}

	public static int parse(String num)
	{
		return Integer.parseInt(num);
	}
}

import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    static Hashtable<Integer, Hashtable<Integer, Integer>> cache;

    public static void putCache(int a, int b, int n) {
        if (cache.containsKey(a)) {
            Hashtable<Integer, Integer> sub = cache.get(a);
            sub.put(b, n);
        } else {
            Hashtable<Integer, Integer> sub = new Hashtable<Integer, Integer>();
            sub.put(b, n);
            cache.put(a, sub);
        }
    }

    public static int dp(int a, int b, int[] k) {
        if (cache.containsKey(a)) {
            Hashtable<Integer, Integer> sub = cache.get(a);
            if (sub.containsKey(b))
                return sub.get(b);
        }
        if (a == b) {
            putCache(a, b, 0);
            return 0;
        }
        boolean found = false;
        for (int i = 0; i < k.length; i++) {
            if (a % k[i] == 0 || b % k[i] == 0) {
                found = true;
                break;
            }
        }
        if (!found) {
            putCache(a, b, -1);
            return -1;
        }
        int res = Integer.MAX_VALUE;
        for (int i = 0; i < k.length; i++) {
            if (a % k[i] == 0) {
                int t = 1 + dp(a / k[i], b, k);
                if (t != 0)
                    res = Math.min(res, t);
            }
            if (b % k[i] == 0) {
                int t = 1 + dp(a, b / k[i], k);
                if (t != 0)
                    res = Math.min(res, t);
            }
        }
        if (res == Integer.MAX_VALUE) {
            putCache(a, b, -1);
            return -1;
        }
        putCache(a, b, res);
        return res;
    }

    public static void main(String args[]) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));
        Scanner scanner = new Scanner(reader);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int[] k = { 2, 3, 5 };
        cache = new Hashtable<Integer, Hashtable<Integer, Integer>>();
        System.out.println(dp(a, b, k));
        reader.close();
    }
}

import java.math.BigInteger;
import java.util.Scanner;

public class FoxDividingCheese {

    public static int gcd(int a,int b) {
        return (BigInteger.valueOf(b).gcd(BigInteger.valueOf(a))).intValue();
    }

    public static int steps235(int x) {
        if (x == 1) return 0;
        int sprev;
        if (x % 2 == 0) sprev = steps235(x/2);
        else if (x % 3 == 0) sprev = steps235(x/3);
        else if (x % 5 == 0) sprev = steps235(x/5);
        else return -1;
        if (sprev == -1) return -1;
        return sprev+1;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt();
        in.close();
        int g = gcd(a,b);
        int ag = a/g, bg = b/g;
        int as = steps235(ag), bs = steps235(bg);
        if (as == -1 || bs == -1) {
            System.out.println(-1);
            return;
        }
        System.out.println(as+bs);
    }

}

//package codeforces;

import java.util.Scanner;

/**
 * Created by nitin.s on 03/04/16.
 */
public class FoxDividingCheese {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int cA = a;
        int[] t = new int[] {2, 3, 5};
        for(int j = 0; j < 3; ++j) {
            while(cA % t[j] == 0) {
                cA /= t[j];
            }
        }
        int cB = b;
        for(int j = 0; j < 3; ++j) {
            while(cB % t[j] == 0) {
                cB /= t[j];
            }
        }
        if(cA != cB) {
            System.out.println(-1);
            return;
        }
        int res = 0;
        for(int j = 0; j < 3; ++j) {
            int f1 = 0;
            while(a % t[j] == 0) {
                a /= t[j];
                ++f1;
            }
            int f2 = 0;
            while(b % t[j] == 0) {
                b /= t[j];
                ++f2;
            }
            res += Math.abs(f1 - f2);
        }
        System.out.println(res);
    }
}

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Created by Timur on 14.12.2016.
 */
public class _371B_radical {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a = in.nextInt();
        int b = in.nextInt();
        int x[] = new int[6];
        int y[] = new int[6];

        solve(a, x);
        solve(b, y);

        out.print(x[0] != y[0] ? -1 : Math.abs(x[2] - y[2]) + Math.abs(x[3] - y[3]) +Math.abs(x[5] - y[5]));
        out.close();
    }

    public static void solve(int x, int counting[]){
        while(x > 0 && x % 2 == 0){
            x /= 2;
            counting[2]++;
        }
        while(x > 0 && x % 3 == 0){
            x /= 3;
            counting[3]++;
        }
        while(x > 0 && x % 5 == 0){
            x /= 5;
            counting[5]++;
        }
        counting[0] = x;
    }
}

import java.io.*;

public class Main {
    private static PrintWriter out = new PrintWriter(System.out);
    private static BufferedReader reading = new BufferedReader(new InputStreamReader(System.in));
    private static StreamTokenizer in = new StreamTokenizer(reading);
    private static int answer = 0;

    private static int getAns(int num)
    {
        num = helpCicle(num, 5);
        num = helpCicle(num, 3);
        num = helpCicle(num, 2);
        return num;
    }

    private static int socZ(int x1, int x2)
    {
        int a;
        while (true)
        {
            a = x1 % x2;
            if (a == 0) return x2;
            x1 = x2;
            x2 = a;
        }
    }

    private static int helpCicle(int num, int z)
    {
        while (true)
        {
            if ((num % z) == 0)
            {
                num /= z;
                answer++;
            }
            else break;
        }
        return num;
    }

    public static void main(String[] args) throws IOException{                  //Coding here
        int[] x = new int[2];
        for(int i = 0; i < x.length; i++){
            x[i] = readInt();
        }
        int sZ;

        if (x[0] == x[1])
        {
            println("0");
        }
        else
        {
            sZ = socZ(x[0], x[1]);
            x[0] /= sZ;
            x[1] /= sZ;
            if ((getAns(x[0]) == 1) && (getAns(x[1]) == 1)) println(answer);
            else println("-1");
        }
    }

    private static int readInt() throws IOException{
        in.nextToken();
        return (int)in.nval;
    }

    private static String readStr() throws IOException{
        in.nextToken();
        return in.sval;
    }

    private static void println(Object o){
        out.println(o);
        out.flush();
    }

    private static void print(Object o){
        out.print(o);
        out.flush();
    }
}

import java.util.*;
import java.io.*;
import java.lang.*;

public class Code90
{

	private static long mod = 1000000007;
	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}
	}

	static class SegmentTree
	{
		int st[];

		SegmentTree(int[] a,int n)
		{
			int x = (int)Math.ceil(Math.log(n)/Math.log(2));

			int Max_Size = 2*(int)(Math.pow(2, x))-1;

			st = new int[Max_Size];

			constructSegTreeUtil(a,0,n-1,0);
		}

		int getMid(int start,int end)
		{
			return (start+end)/2;
		}

		int constructSegTreeUtil(int[] a,int ss,int se,int si)
		{
			if(ss==se)
			{
				st[si] = a[ss];
				return a[ss];
			}

			int mid = getMid(ss, se);
			st[si] = constructSegTreeUtil(a, ss, mid, 2*si+1)+
						constructSegTreeUtil(a, mid+1, se, 2*si+2);

			return st[si];
		}

		int getSum(int n, int qs, int qe)
		{
			if(qs<0 || qe>n-1 || qs>qe)
				return -1;

			return getSumUtil(0,n-1,qs,qe,0);
		}

		int getSumUtil(int ss, int se,int qs, int qe, int si)
		{
			if(qs<=ss && qe>=se)
				return st[si];

			if(qs>se || qe<ss)
				return 0;

			int mid = getMid(ss, se);

			return getSumUtil(ss, mid, qs, qe, 2*si+1)+
					getSumUtil(mid+1, se, qs, qe, 2*si+2);
		}

		void updateValue(int[] a, int n, int i, int new_value)
		{
			if(i<0 || i>n-1)
				return;

			int diff = new_value - a[i];

			a[i] = new_value;

			updateValueUtil(0,n-1,i,diff,0);
		}

		void updateValueUtil(int ss, int se, int i, int diff, int si)
		{
			if(i<ss || i>se)
				return;

			st[si]+=diff;
			if(ss!=se)
			{
				int mid = getMid(ss, se);
				updateValueUtil(ss, mid+1, i, diff, 2*si+1);
				updateValueUtil(mid+1, se, i, diff, 2*si+2);
			}
		}
	}

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static ArrayList<Integer> primeFactorization(int n)
	{
		ArrayList<Integer> a =new ArrayList<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(i*i);j<n;j++)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long GCD(long a,long b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static ArrayList<Integer> getPrime(int n)
	{
		ArrayList<Integer> primes = new ArrayList<>();
		int count = 0;
		while(n%2==0)
		{
			count++;
			n/=2;
		}
		primes.add(count);

		count = 0;
		while(n%3==0)
		{
			count++;
			n/=3;
		}
		primes.add(count);

		count = 0;
		while(n%5==0)
		{
			count++;
			n/=5;
		}
		primes.add(count);

		primes.add(n);

		return primes;
	}
	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int a = in.nextInt();
		int b = in.nextInt();

		ArrayList<Integer> A = new ArrayList<>();
		ArrayList<Integer> B = new ArrayList<>();

		A = getPrime(a);
		B = getPrime(b);

		int ans = 0;
		for(int i=0;i<3;i++)
			ans+=(int)(Math.abs(A.get(i)-B.get(i)));

		if((int)A.get(3) == (int)B.get(3))
			pw.println(ans);
		else
			pw.println("-1");
		pw.flush();
		pw.close();
	}
}

import java.io.*;
import java.util.*;
public class Main
{

	private void solve()throws Exception
	{
		int a=nextInt();
		int b=nextInt();
		int f1[]=new int[6];
		int f2[]=new int[6];
		int f[]={2,3,5};
		for(int i=0;i<3;i++)
		{
			while(a%f[i]==0)
			{
				f1[f[i]]++;
				a=a/f[i];
			}
			while(b%f[i]==0)
			{
				f2[f[i]]++;
				b=b/f[i];
			}
		}
		if(a!=b)
		{
			out.println(-1);
			return;
		}
		int ans=0;
		for(int i=0;i<3;i++)
			ans+=Math.abs(f1[f[i]]-f2[f[i]]);
		out.println(ans);
	}

	///////////////////////////////////////////////////////////

	public void run()throws Exception
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();

		br.close();
		out.close();
	}
	public static void main(String args[])throws Exception{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws Exception{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws Exception{
		return br.readLine();
	}
	int nextInt()throws Exception{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws Exception{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws Exception{
		return Double.parseDouble(nextToken());
	}
}

    import java.util.*;
    import java.lang.*;
    import java.io.*;
   public class Solution {
       public static void main(String args[]){

       Scanner sc=new Scanner(System.in);
       int a=sc.nextInt();
       int b=sc.nextInt();
       int a1=0,b1=0,c1=0;
       while(a%2==0){
           a1++;
           a=a/2;
       }
       while(a%3==0){
           a=a/3;
           b1++;
       }
       while(a%5==0){
           a=a/5;
           c1++;
       }
       int a2=0,b2=0,c2=0;
        while(b%2==0){
           a2++;
           b=b/2;
       }
       while(b%3==0){
           b=b/3;
           b2++;
       }
       while(b%5==0){
           b=b/5;
           c2++;
       }
       if(a==b){
           int ans=Math.abs(a1-a2)+Math.abs(b1-b2)+Math.abs(c1-c2);
           System.out.println(ans);
       }
       else
       System.out.println("-1");

    }}

import java.util.Scanner;

public class B2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int ops = 0;
		if(a < b){
			int temp = a;
			a = b;
			b = temp;
		}

			for(int i = 2; i < 6; i++){
				while(a%i == 0 && b%i == 0){
					a/=i; b /=i;
				}
				while(a%i == 0 && b%i != 0){
					a /= i;
					ops++;
				}
				while(a%i != 0 && b%i == 0){
					b /= i;
					ops++;
				}
			}

			if(a != b){
				System.out.println(-1);
			}
			else System.out.println(ops);

	}

}

import java.io.*;
import java.util.StringTokenizer;

public class A {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a = sc.nextInt(), b = sc.nextInt(), gcd = gcd(a, b);
        int fa = factorize(a / gcd), fb = factorize(b / gcd);
        out.println(fa == -1 || fb == -1? -1 : fa + fb);
        out.flush();
        out.close();
    }

    static int factorize(int x) {
        int count = 0;
        for (int i = 2; i < 6; i++)
            while (x % i == 0) {x /= i; count++;}
        return x == 1? count : -1;
    }

    static int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    static class Scanner
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));}
        public Scanner(String file) throws Exception {br = new BufferedReader(new FileReader(file));}
        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        public String nextLine()throws IOException{return br.readLine();}
        public int nextInt() throws IOException {return Integer.parseInt(next());}
        public double nextDouble() throws IOException {return Double.parseDouble(next());}
        public char nextChar()throws IOException{return next().charAt(0);}
        public Long nextLong()throws IOException{return Long.parseLong(next());}
        public boolean ready() throws IOException{return br.ready();}
        public void waitForInput() throws InterruptedException {Thread.sleep(4000);}
    }
}

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class FoxDividingCheese {
	public int equal(int a,int b) {
		if(a==b) {
			return 0;
		}
		int counter=0;
		Map<Integer,Integer>mp1=new HashMap<>();
		Map<Integer,Integer>mp2=new HashMap<>();
		mp1.put(2,0); mp1.put(3,0);  mp1.put(5,0);

		mp2.put(2,0); mp2.put(3,0);  mp2.put(5,0);

		while(a!=1) {
			if(a%2!=0 && a%3!=0 && a%5!=0) {
				break;
			}
			if(a%2==0) {
				a=a/2;
				mp1.put(2,mp1.get(2)+1);
			}
			else if(a%3==0) {
				a=a/3;
				mp1.put(3,mp1.get(3)+1);
			}
			else if(a%5==0) {
				a=a/5;
				mp1.put(5,mp1.get(5)+1);
			}
		}

		while(b!=1) {
			if(b%2!=0 && b%3!=0 && b%5!=0) {
				break;
			}
			if(b%2==0) {
				b=b/2;
				mp2.put(2,mp2.get(2)+1);
			}
			else if(b%3==0) {
				b=b/3;
				mp2.put(3,mp2.get(3)+1);
			}
			else if(b%5==0) {
				b=b/5;
				mp2.put(5,mp2.get(5)+1);
			}
		}
		if(a!=b) {
			return -1;
		}

		counter+=Math.abs(mp1.get(2)-mp2.get(2));
		counter+=Math.abs(mp1.get(3)-mp2.get(3));
		counter+=Math.abs(mp1.get(5)-mp2.get(5));
		return counter;
	}

	public static void main(String[]args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		FoxDividingCheese ob=new FoxDividingCheese();
		System.out.println(ob.equal(a, b));
	}
}

import java.util.Scanner;

public class B371 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
int n = sc.nextInt();
int m=sc.nextInt();
int a[]=new int[3];
int b[]=new int[3];

a[0]=method(n,2);
a[1]=method(n,3);
a[2]=method(n,5);

b[0]=method(m,2);
b[1]=method(m,3);
b[2]=method(m,5);

if(n==m)
	System.out.println(0);
else if(method1(n,a)!=method1(m,b))
	System.out.println(-1);
else
	System.out.println(Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1])+Math.abs(a[2]-b[2]));

	}
static int method(int x, int y){
	int count=0;
	while(x%y==0){
		x=x/y;
		count++;
	}
	return count;

}
static int method1(int x, int[] y){

	return (int) (x/(Math.pow(2, y[0])*Math.pow(3, y[1])*Math.pow(5, y[2])));

}

}

import java.util.Scanner;

public class CF371_D2_B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (a == b) {
            System.out.println("0");
            return;
        }
        int count = 0;
        boolean change = true;
        int gcd = gcd(a, b);
//        System.out.println(gcd);
        a = a / gcd;
        if (!(a > 5 && isPrime(a) && gcd == 1)) {
            while (a > 1 && change) {
                change = false;
                if (a % 2 == 0) {
                    a = a / 2;
                    change = true;
                    count++;
                } else if (a % 3 == 0) {
                    a = a / 3;
                    change = true;
                    count++;
                } else if (a % 5 == 0) {
                    a = a / 5;
                    change = true;
                    count++;
                }
            }
        }

        b = b / gcd;
        if (!(b > 5 && isPrime(b) && gcd == 1))
            while (b > 1 && change) {
                change = false;
                if (b % 2 == 0) {
                    b = b / 2;
                    change = true;
                    count++;
                } else if (b % 3 == 0) {
                    b = b / 3;
                    change = true;
                    count++;
                } else if (b % 5 == 0) {
                    b = b / 5;
                    change = true;
                    count++;
                }
            }
        if (a == 1 && b == 1)
            System.out.println(count);
        else
            System.out.println("-1");
    }

    static boolean isPrime(int m) {
        for (int i = 2; i * i < m; i++) {
            if (m % i == 0) {
                return false;
            }
        }
        return true;
    }

    static int gcd(int n1, int n2) {
        if (n2 == 0) {
            return n1;
        }
        return gcd(n2, n1 % n2);
    }
}

import java.util.Scanner;

public class _371B {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		scanner.close();

		if (a == b) {
			System.out.print(0);
			return;
		}
		int[] del = {2, 3, 5};
		int[] del_a = new int[del.length];
		int[] del_b = new int[del.length];

		for (int i = 0; i < del.length; i++) {
			while (a % del[i] == 0) {
				del_a[i]++;
				a /= del[i];
			}

			while (b % del[i] == 0) {
				del_b[i]++;
				b /= del[i];
			}
		}

		if (a != b) {
			System.out.print(-1);
			return;
		}
		int sum = 0;
		for (int i = 0; i < del.length; i++) {
			sum += Math.abs(del_b[i] - del_a[i]);
		}
		System.out.print(sum);
	}
}

import java.util.Scanner;
public class cheese371B
{
    public int hcf(int a,int b)
    {
        if(b==0)
            return a;
        return hcf(b,a%b);
    }
    public static void main(String args[])
    {
        Scanner s =new Scanner(System.in);
        cheese371B cb=new cheese371B();
        int a,b;
        a=s.nextInt();
        b=s.nextInt();
        int ans=0;
        int ansa=0,ansb=0;
        //hcf
        int tmp = cb.hcf(a,b);
        int tmpa,tmpb;
        tmpa=a/tmp;
        tmpb=b/tmp;
        if(tmpa!=1)
        {
            while(tmpa%2==0)
            {
                ++ansa;
                tmpa=tmpa/2;
            }
        }
        if(tmpa!=1)
        {
            while(tmpa%3==0)
            {
                ++ansa;
                tmpa=tmpa/3;
            }
        }
        if(tmpa!=1)
        {
            while(tmpa%5==0)
            {
                ++ansa;
                tmpa=tmpa/5;
            }
        }
        if(tmpa!=1)
        {
            ans=-1;
        }
        if(tmpb!=1)
        {
            while(tmpb%2==0)
            {
                ++ansb;
                tmpb=tmpb/2;
            }
        }
        if(tmpb!=1)
        {
            while(tmpb%3==0)
            {
                ++ansb;
                tmpb=tmpb/3;
            }
        }
        if(tmpb!=1)
        {
            while(tmpb%5==0)
            {
                ++ansb;
                tmpb=tmpb/5;
            }
        }
        if(tmpb!=1)
        {
            ans=-1;
        }
        if(ans!=-1)
        {
            ans=ansa+ansb;
        }
        System.out.println(ans);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.AbstractCollection;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int a = in.nextInt();
            int b = in.nextInt();
            Pair start = new Pair(a, b, 0);
            int result = solve(start);
            out.println(result);
        }

        public int solve(Pair pair)
        {
            TreeSet<Pair> was = new TreeSet<>();
            LinkedList<Pair> q = new LinkedList<Pair>();

            was.add(pair);
            q.add(pair);

            while (!q.isEmpty())
            {
                Pair p = q.pollFirst();
                if (p.a == p.b)
                {
                    return p.level;
                }
                if (p.b % 2 == 0)
                {
                    Pair p1 = new Pair(p.a, p.b / 2, p.level + 1);
                    if (!was.contains(p1))
                    {
                        q.add(p1);
                        was.add(p1);
                    }
                }
                if (p.b % 3 == 0)
                {
                    Pair p2 = new Pair(p.a, p.b / 3, p.level + 1);
                    if (!was.contains(p2))
                    {
                        q.add(p2);
                        was.add(p2);
                    }
                }
                if (p.b % 5 == 0)
                {
                    Pair p3 = new Pair(p.a, p.b / 5, p.level + 1);
                    if (!was.contains(p3))
                    {
                        q.add(p3);
                        was.add(p3);
                    }
                }
            }
            return -1;
        }

        class Pair implements Comparable<Pair>
        {
            int a;
            int b;
            int level;

            public Pair(int a, int b, int level)
            {
                this.a = Math.min(a, b);
                this.b = Math.max(a, b);
                this.level = level;
            }

            public int compareTo(Pair that)
            {
                int aDiff = Integer.compare(this.a, that.a);
                return aDiff != 0 ? aDiff : Integer.compare(this.b, that.b);
            }

        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }

    static class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

    }
}

import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Nguyen Trung Hieu - vuondenthanhcong11@yahoo.com
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int a = in.readInt();
        int b = in.readInt();
        int gcd = IntegerUtils.gcd(a, b);
        a /= gcd;
        b /= gcd;
        int answer = 0;
        while (a > 1) {
            answer++;
            if (a % 2 == 0)
                a /= 2;
            else if (a % 3 == 0)
                a /= 3;
            else if (a % 5 == 0)
                a /= 5;
            else {
                out.printLine(-1);
                return;
            }
        }

        while (b > 1) {
            answer++;
            if (b % 2 == 0)
                b /= 2;
            else if (b % 3 == 0)
                b /= 3;
            else if (b % 5 == 0)
                b /= 5;
            else {
                out.printLine(-1);
                return;
            }
        }

        out.printLine(answer);
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }

    }

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

}

class IntegerUtils {

    public static int gcd(int a, int b) {
        a = Math.abs(a);
        b = Math.abs(b);
        while (b != 0) {
            int temp = a % b;
            a = b;
            b = temp;
        }
        return a;
    }

    }

import java.io.*;
import java.util.*;
public final class running_track
{
	static Scanner sc=new Scanner(System.in);
	static PrintWriter out=new PrintWriter(System.out);

	public static void main(String args[]) throws Exception
	{
		long n=sc.nextLong(),m=sc.nextLong();
		List<Long> list1=new ArrayList<Long>(),list2=new ArrayList<Long>();
		long[] a=new long[]{2,3,5};
		int i=0;
		while(i<3 && n>1)
		{
			if(n%a[i]==0)
			{
				n/=a[i];
				list1.add(a[i]);
			}
			else
			{
				if(i==2)
				{
					list1.add(n);
				}
				i++;
			}
		}
		i=0;
		while(i<3 && m>1)
		{
			if(m%a[i]==0)
			{
				m/=a[i];
				list2.add(a[i]);
			}
			else
			{
				if(i==2)
				{
					list2.add(m);
				}
				i++;
			}
		}
		boolean[] v1=new boolean[list1.size()],v2=new boolean[list2.size()];
		for(i=0;i<list1.size();i++)
		{
			long curr=list1.get(i);
			for(int j=0;j<list2.size();j++)
			{
				if(!v2[j] && curr==list2.get(j))
				{
					v1[i]=true;
					v2[j]=true;
					break;
				}
			}
		}
		int c=0;
		boolean ans=true;
		for(i=0;i<list1.size();i++)
		{
			if(!v1[i])
			{
				if(list1.get(i)==2 || list1.get(i)==3 || list1.get(i)==5)
				{
					c++;
				}
				else
				{
					ans=false;
					break;
				}
			}
		}
		for(i=0;i<list2.size();i++)
		{
			if(!v2[i])
			{
				if(list2.get(i)==2 || list2.get(i)==3 || list2.get(i)==5)
				{
					c++;
				}
				else
				{
					ans=false;
					break;
				}
			}
		}
		out.println((ans)?c:"-1");
		out.close();
	}
}

/*
 *
 *   Date: 07 September 2019
 *   Time: 01:03:00
*/
import java.io.*;
import java.util.*;

public class fd
{
static int n,m,res;
   static void check(int p){
       int u = 0;int v = 0;
       while(n%p==0){u++;n/=p;}
       while(m%p==0){v++;m/=p;}
       res+= Math.abs(u-v);
   }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         n = sc.nextInt();
         m = sc.nextInt();
         res = 0;
         check(3);check(5);check(2);
         if(n==m) System.out.println(res);
         else System.out.println(-1);

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BFoxDividingCheese solver = new BFoxDividingCheese();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFoxDividingCheese {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (a == b) {
                out.println(0);
                return;
            }
            int ans = 0;
            int nba5 = 0;
            int nbb5 = 0;
            while (a % 5 == 0) {
                a /= 5;
                nba5++;
            }
            while (b % 5 == 0) {
                b /= 5;
                nbb5++;
            }
            ans += Math.abs(nba5 - nbb5);
            int nba3 = 0;
            int nbb3 = 0;
            while (a % 3 == 0) {
                a /= 3;
                nba3++;
            }
            while (b % 3 == 0) {
                b /= 3;
                nbb3++;
            }
            ans += Math.abs(nba3 - nbb3);
            int nba2 = 0;
            int nbb2 = 0;
            while (a % 2 == 0) {
                a /= 2;
                nba2++;
            }
            while (b % 2 == 0) {
                b /= 2;
                nbb2++;
            }
            ans += Math.abs(nba2 - nbb2);
            if (a == b) {
                out.println(ans);
            } else {
                out.println(-1);
            }

        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.util.Scanner;

public class FoxDividingCheese {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        int gcd = GCD(a, b);
        int aStep = primeFactorizationSteps(a / gcd);
        int bStep = primeFactorizationSteps(b / gcd);
        if (aStep != -1 && bStep != -1) {
            System.out.println(aStep + bStep);
        } else {
            System.out.println(-1);
        }
    }

    public static int GCD(int a, int b) {
        if (a == 0) {
            return b;
        }
        if (b == 0) {
            return a;
        }
        return GCD(b, a % b);
    }

    public static int primeFactorizationSteps(int a) {
        int steps = 0;
        while (a % 2 == 0) {
            steps++;
            a = a / 2;
        }

        while(a % 3 == 0) {
            steps++;
            a = a / 3;
        }

        while(a % 5 == 0) {
            steps++;
            a = a / 5;
        }
        if (a != 1) {
            return -1;
        } else {
            return steps;
        }
    }
}

import java.util.*;
import java.lang.Math;
public class Problem2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int v5n = 0;
        int v5k = 0;
        int v3n = 0;
        int v3k = 0;
        int v2n = 0;
        int v2k = 0;
        while(n % 5 == 0) {
            n /= 5;
            v5n++;
        }
        while(n % 3 == 0) {
            n /= 3;
            v3n++;
        }
        while(n % 2 == 0) {
            n /= 2;
            v2n++;
        }
        while(k % 5 == 0) {
            k /= 5;
            v5k++;
        }
        while(k % 3 == 0) {
            k /= 3;
            v3k++;
        }
        while(k % 2 == 0) {
            k /= 2;
            v2k++;
        }
        if(k != n)
            System.out.println("-1");
        else {
            int ans = Math.abs(v5n - v5k) + Math.abs(v3n - v3k) + Math.abs(v2n - v2k);
            System.out.println(ans);
        }
    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;

public class B
{
        String line;
        StringTokenizer inputParser;
        BufferedReader is;
        FileInputStream fstream;
        DataInputStream in;
        String FInput="";

        void openInput(String file)
        {

                if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
                else
                {
                        try{

                        fstream = new FileInputStream(file);
                        in = new DataInputStream(fstream);
                        is = new BufferedReader(new InputStreamReader(in));
                        }catch(Exception e)
                        {
                                System.err.println(e);
                        }
                }

        }

        void readNextLine()
    	{
    		try {
    			line = is.readLine();
    			inputParser = new StringTokenizer(line, " ,\t");
    			//System.err.println("Input: " + line);
    		} catch (IOException e) {
    			System.err.println("Unexpected IO ERROR: " + e);
    		}
    		catch (NullPointerException e)
    		{
    			line=null;

    		}

    	}

        long NextLong()
        {
                String n = inputParser.nextToken();

                long val = Long.parseLong(n);

                 return val;
        }

        int NextInt()
        {
                String n = inputParser.nextToken();
                int val = Integer.parseInt(n);

                //System.out.println("I read this number: " + val);
                return val;
        }

        String NextString()
        {
                String n = inputParser.nextToken();
                return n;
        }

        void closeInput()
        {
                try {
                        is.close();
                } catch (IOException e) {
                        System.err.println("Unexpected IO ERROR: " + e);
                }

        }

        public static void main(String [] argv)
        {
                //String filePath="circles.in";
                String filePath=null;
                if(argv.length>0)filePath=argv[0];
                new B(filePath);

        }

        public B(String inputFile)
        {
        	openInput(inputFile);
    		StringBuilder sb = new StringBuilder();
    		readNextLine();
        	int N=NextInt(), M=NextInt();
        	TreeMap <Integer, Integer>n = new TreeMap<Integer, Integer>();
        	TreeMap <Integer, Integer>m = new TreeMap<Integer, Integer>();

        	ArrayList <State>q = new ArrayList<State>();
        	q.add(new State(0, N));
        	while(!q.isEmpty())
        	{
        		State x=q.remove(0);
        		if(n.containsKey(x.val))continue;
        		n.put(x.val, x.steps);
        		if(x.val%2==0)
        		{
        			q.add(new State(x.steps+1, x.val/2));
        		}
        		if(x.val%3==0)
        		{
        			q.add(new State(x.steps+1, x.val/3));
        		}
        		if(x.val%5==0)
        		{
        			q.add(new State(x.steps+1, x.val/5));
        		}
        	}

        	q = new ArrayList<State>();
        	q.add(new State(0, M));
        	while(!q.isEmpty())
        	{
        		State x=q.remove(0);
        		if(m.containsKey(x.val))continue;
        		m.put(x.val, x.steps);
        		if(x.val%2==0)
        		{
        			q.add(new State(x.steps+1, x.val/2));
        		}
        		if(x.val%3==0)
        		{
        			q.add(new State(x.steps+1, x.val/3));
        		}
        		if(x.val%5==0)
        		{
        			q.add(new State(x.steps+1, x.val/5));
        		}
        	}

        	int ret=Integer.MAX_VALUE;

        	for(int x:n.keySet())
        	{
        		if(m.containsKey(x))
        		{
        			ret=Math.min(ret, m.get(x)+n.get(x));
        		}
        	}

        	if(ret==Integer.MAX_VALUE)ret=-1;
        	sb.append(ret);

        	System.out.println(sb);
    		closeInput();

        }

        private class State
        {
        	int steps, val;

        	State(int steps, int val)
        	{
        		this.steps=steps;
        		this.val=val;

        	}
        }

}

import java.util.Scanner;

public class FoxDividingCheese {
    public static void main(String asd[])throws Exception
    {
        Scanner in=new Scanner(System.in);
        int a=in.nextInt();
        int b=in.nextInt();
        if(a==b)
            System.out.println(0);
        else
        {
            if(a>b)
            {
                int c=a;
                a=b;
                b=c;
            }
            int r=a;int q=b;
            while(a!=0)
            {
                int c=b%a;
                b=a;
                a=c;
            }
            int y=b;
            r/=y;
            q/=y;int cc=0;
            while(r!=1 && r%2==0)
            {
                r/=2;
                cc+=1;
            }
            while(r!=1 && r%3==0)
            {
                r/=3;
                cc+=1;
            }
            while(r!=1 && r%5==0)
            {
                r/=5;
                cc+=1;
            }
            while(q!=1 && q%2==0)
            {
                q/=2;
                cc+=1;
            }
            while(q!=1 && q%3==0)
            {
                q/=3;
                cc+=1;
            }
            while(q!=1 && q%5==0)
            {
                q/=5;
                cc+=1;
            }
            if(r==1 && q==1)
                System.out.println(cc);
            else
                System.out.println(-1);
        }
    }
}

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long a = in.nextLong();
        long b = in.nextLong();
        if (a == b) {
            out.println(0);
            return;
        }
        long g = gcd(a, b);
        long foo = calc(a / g);
        long bar = calc(b / g);
        if (foo == -1 || bar == -1) {
            out.println(-1);
        } else {
            out.println(foo + bar);
        }
    }

    long calc(long a) {
        HashMap<Long, Integer> factors = factorize(a);
        long res = 0;
        for (Long factor : factors.keySet()) {
            if (factor != 2 && factor != 3 && factor != 5) return -1;
            res += factors.get(factor);
        }
        return res;
    }

    public HashMap<Long, Integer> factorize(long n) {
        HashMap<Long, Integer> factors = new HashMap<Long, Integer>();
        for (long d = 2; n > 1; ) {
            int power = 0;
            while (n % d == 0) {
                ++power;
                n /= d;
            }
            if (power > 0) {
                factors.put(d, power);
            }
            ++d;
            if (d * d > n) {
                d = n;
            }
        }
        return factors;
    }

    public long gcd(long a, long b) {
        while (b != 0) {
            long t = b;
            b = a % b;
            a = t;
        }
        return Math.abs(a);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

}

import java.io.*;
import java.util.*;

public class cf371b {
  static FastIO in = new FastIO(), out = in;

  public static void main(String[] args) {
    Map<Integer,Integer> a = dist(in.nextInt()), b = dist(in.nextInt());
    int ret = (int)1e9;
    for(int x : a.keySet())
      if(b.containsKey(x))
        ret = Math.min(ret, a.get(x) + b.get(x));
    if(ret == (int)1e9) ret = -1;
    out.println(ret);
    out.close();
  }

  static Map<Integer,Integer> dist(int x) {
    ArrayDeque<Integer> q = new ArrayDeque<Integer>();
    q.add(x);
    Map<Integer,Integer> map = new HashMap<Integer,Integer>();
    map.put(x,0);
    while(!q.isEmpty()) {
      int z = q.poll();
      int d = map.get(z);
      for(int i=2; i<=5; i++)
        if(i != 4 && z%i == 0 && !map.containsKey(z/i)) {
          map.put(z/i, d+1);
          q.add(z/i);
        }
    }
    return map;
  }

  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;

    public FastIO() {
      this(System.in, System.out);
    }

    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }

    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }

    public int numTokens() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }

    public String next() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}

import java.util.*;
public class twenty{
	public static void main(String[] args) {
		Scanner scn =new Scanner(System.in);
		int a= scn.nextInt();
		int b= scn.nextInt();
		int a3=0,a5=0,a2=0;
		int b3=0,b5=0,b2=0;

		while(a%3==0)
		{
			a/=3;
			a3++;
		}
		while(a%2==0)
		{
			a/=2;
			a2++;
		}
		while(a%5==0)
		{
			a/=5;
			a5++;
		}

		while(b%3==0)
		{
			b/=3;
			b3++;
		}
		while(b%2==0)
		{
			b/=2;
			b2++;
		}
		while(b%5==0)
		{
			b/=5;
			b5++;
		}

		// System.out.println("a="+a+"b="+b);
		int count=0;
		if(a==b)
		{
			count=Math.abs(a2-b2) +Math.abs(a3-b3)+Math.abs(a5-b5);
		}
		else
		{
			count=-1;
		}
System.out.println(count);

		// System.out.println("a="+a+"b="+b);
		// int count=0;
		// boolean modified=true;
		// // System.out.println("check point 1");

		// while(a!=b &&modified)
		// {

		// 	// System.out.println("a="+a+"b="+b);
		// 	count++;
		// 	modified=false;
		// 	if(a%2==0)
		// 	{
		// 		a=a/2;
		// 		modified=true;
		// 	}
		// 	else if(a%3==0)
		// 	{
		// 		a=a/3;
		// 		modified=true;
		// 	}
		// 	else if(a%5==0)
		// 	{
		// 		a=a/5;
		// 		modified=true;
		// 	}
		// 	if(b%2==0)
		// 	{
		// 		b=b/2;
		// 		modified=true;
		// 	}
		// 	else if(b%3==0)
		// 	{
		// 		b=b/3;
		// 		modified=true;
		// 	}
		// 	else if(b%5==0)
		// 	{
		// 		b=b/5;
		// 		modified=true;
		// 	}
		// 	// count++;
		// }
		// // System.out.println("after while loop");
		// if(a==b)
		// {
		// 	System.out.println(count);
		// }
		// else
		// {
		// 	System.out.println(-1);
		// }

	}
}

import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Created by Timur on 14.12.2016.
 */
public class _371B_radical {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a = in.nextInt();
        int b = in.nextInt();
        int x[] = new int[6];
        int y[] = new int[6];

        solve(a, x);
        solve(b, y);

        out.print(x[0] != y[0] ? -1 : Math.abs(x[2] - y[2]) + Math.abs(x[3] - y[3]) +Math.abs(x[5] - y[5]));
        out.close();
    }

    public static void solve(int x, int counting[]){
        while(x > 0 && x % 2 == 0){
            x /= 2;
            counting[2]++;
        }
        while(x > 0 && x % 3 == 0){
            x /= 3;
            counting[3]++;
        }
        while(x > 0 && x % 5 == 0){
            x /= 5;
            counting[5]++;
        }
        counting[0] = x;
    }
}

import java.util.*;
import java.io.*;

public class Codeforces {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int[][] arr = new int [2][3];

        a = fillArray(a, arr[0]);
        b = fillArray(b , arr[1]);

        if( a != b){
            System.out.println(-1);
            return;
        }

        int res = Math.abs(arr[0][0] - arr[1][0]) + Math.abs(arr[0][1] - arr[1][1]) + Math.abs(arr[0][2] - arr[1][2]);
        System.out.println(res);
    }

    private static int fillArray(int n, int[] arr){
        boolean isOk = true;
        while(isOk){
            if(n % 2 == 0){
                n /= 2;
                arr[0]++;
                continue;
            }
            if(n % 3 == 0){
                n /= 3;
                arr[1]++;
                continue;
            }
            if(n % 5 == 0){
                n /= 5;
                arr[2]++;
                continue;
            }
            isOk = false;
        }
        return n;
    }
}

import java.io.*;
import java.util.*;
public class FoxDividingCheese
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    static class OutputWriter
    {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream)
        {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer)
        {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object...objects)
        {
            for (int i = 0; i < objects.length; i++)
            {
                if (i != 0)
                    writer.print(' ');
                writer.print(objects[i]);
            }
        }

        public void printLine(Object...objects)
        {
            print(objects);
            writer.println();
        }

        public void close()
        {
            writer.close();
        }

        public void flush() {
            writer.flush();
        }
    }
    static int gcd(int a, int b)
    {
        if(a==0)
            return b;
        return gcd(b%a,a);
    }
    static int pfactorization(int x)
    {
        int f=0;
        while(x%2==0)
        {
            f++;
            x=x/2;
        }
        for(int i=3;i<=x;i+=2)
        {
            if(x%i==0)
            {
                if(i>5)
                {
                    f=-1;
                    break;
                }
                else
                {
                    while(x%i==0)
                    {
                        f++;
                        x/=i;
                    }
                }
            }
        }
        return f;
    }
    public static void main(String args[])
    {
        FastReader sc=new FastReader();
        OutputWriter out=new OutputWriter(System.out);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a==b)
        {
            out.printLine(0);
            out.flush();
            System.exit(0);
        }
        if(a%2!=0 && a%3!=0 && a%5!=0 && b%2!=0 && b%3!=0 && b%5!=0)
        {
            out.printLine(-1);
            out.flush();
            System.exit(0);
        }
        int hcf=gcd(a,b);
        int count=0;
        int ac=a/hcf,bc=b/hcf;
        int ar=pfactorization(ac);
        int br=pfactorization(bc);
        if(a%hcf==0 && b%hcf==0 && ar!=-1 && br!=-1)
            out.printLine(ar+br);
        else
            out.printLine(-1);
        out.flush();
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author el-Bishoy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Div2B_371_FoxDividingCheeze solver = new Div2B_371_FoxDividingCheeze();
        solver.solve(1, in, out);
        out.close();
    }

    static class Div2B_371_FoxDividingCheeze {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int a = in.nextInt(), b = in.nextInt();

            int cnt = 0, cnt2 = 0;

            long gcd = gcd(a, b);
            cnt = getCount(a / gcd);
            cnt2 = getCount(b / gcd);
            if (cnt == -1 || cnt2 == -1) {
                out.println(-1);
                return;
            }
            out.println(cnt + cnt2);

        }

        private int getCount(long n) {
            boolean f = true;
            int cnt = 0;
            while (f) {
                f = false;
                if (n % 2 == 0) {
                    cnt++;
                    f = true;
                    n /= 2;
                }
                if (n % 3 == 0) {
                    cnt++;
                    f = true;
                    n /= 3;
                }
                if (n % 5 == 0) {
                    cnt++;
                    f = true;
                    n /= 5;
                }

            }

            return n == 1 ? cnt : -1;
        }

        long gcd(long a, long b) {

            if (b == 0)
                return a;

            return gcd(b, a % b);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.*;
import java.io.*;

public class B371 {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int a = sc.nextInt(), b = sc.nextInt();
		int[][] c = new int[2][3];
		while(a % 2 == 0) {
			a /= 2;
			c[0][0]++;
		}
		while(a % 3 == 0) {
			a /= 3;
			c[0][1]++;
		}
		while(a % 5 == 0) {
			a /= 5;
			c[0][2]++;
		}
		while(b % 2 == 0) {
			b /= 2;
			c[1][0]++;
		}
		while(b % 3 == 0) {
			b /= 3;
			c[1][1]++;
		}
		while(b % 5 == 0) {
			b /= 5;
			c[1][2]++;
		}

		if(a != b)
			pw.println(-1);
		else {
			int cnt = 0;
			cnt += Math.abs(c[0][0] - c[1][0]);
			cnt += Math.abs(c[0][1] - c[1][1]);
			cnt += Math.abs(c[0][2] - c[1][2]);
			pw.println(cnt);
		}

		pw.flush();
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

import java.util.Scanner;

public class Main{

	private static Scanner input;
	private static int a,b;
	private static int[] divs = {2,3,5,6};
	private static int[] values = {0,0,0,0,0,0};

	public static void main(String[] args) {
		input = new Scanner(System.in);
		a = input.nextInt();
		b = input.nextInt();
		int ia=0, ib=0;
		while(ia<4 || ib<4){
			if(ia<4){
				if(a%divs[ia] == 0){
					values[ia]++;
					a /= divs[ia];
				}else{
					ia++;
				}
			}
			if(ib<4){
				if(b%divs[ib] == 0){
					values[ib+3]++;
					b /= divs[ib];
				}else{
					ib++;
				}
			}
		}
		if(a == b){
			System.out.println(Math.abs(values[0]-values[3]) + Math.abs(values[1]-values[4]) + Math.abs(values[2]-values[5]));
		}
		else{
			System.out.println(-1);
		}

	}

}

import java.util.Scanner;

public class FoxDividingCheese
{
	public static int HasNum(int n, int[] res, int[] num)
	{
		for (int i = 0; i < num.length; ++i)
		{
			while (n % num[i] == 0)
			{
				n /= num[i];
				++res[i];
			}
		}
		return n;
	}

	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		int a = input.nextInt();
		int b = input.nextInt();
		int[] num = {2, 3, 5};
		int len = num.length;
		int[] numOfa = new int[len];
		int[] numOfb = new int[len];
		for (int i = 0; i < len; ++i)
		{
			numOfa[i] = 0;
			numOfb[i] = 0;
		}
		a = HasNum(a, numOfa, num);
		b = HasNum(b, numOfb, num);
		if (a != b)
		{
			System.out.println(-1);
			return;
		}
		int sum = 0;
		for (int i = 0; i < len; ++i)
		{
			sum += numOfa[i] > numOfb[i] ? numOfa[i] - numOfb[i] : numOfb[i] - numOfa[i];
		}
		System.out.println(sum);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class B
{

    public static void main(String[] args)
    {
        MyScanner in = new MyScanner();

        int a = in.nextInt();
        int b = in.nextInt();

        int ans = 0;

        int[] factors = new int[6];

        for (int i = 2; i <= 5; i++)
        {

            if (i == 4)
                continue;

            while (a > 0 && a % i == 0)
            {
                factors[i]++;
                a = a / i;
            }

            while (b > 0 && b % i == 0)
            {
                factors[i]--;
                b = b / i;
            }

        }

        if (a == b)
        {
            for (int i = 0; i < factors.length; i++)
            {
                ans += Math.abs(factors[i]);
            }
            System.out.println(ans);
        }
        else
        {
            System.out.println(-1);
        }

    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner
    {
        BufferedReader  br;
        StringTokenizer st;

        public MyScanner()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}

import java.util.Scanner;

public class CF371_D2_B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (a == b) {
            System.out.println("0");
            return;
        }
        int count = 0;
        boolean change = true;
        int gcd = gcd(a, b);
//        System.out.println(gcd);
        a = a / gcd;
        while (a > 1 && change) {
            change = false;
            if (a % 2 == 0) {
                a = a / 2;
                change = true;
                count++;
            } else if (a % 3 == 0) {
                a = a / 3;
                change = true;
                count++;
            } else if (a % 5 == 0) {
                a = a / 5;
                change = true;
                count++;
            }
        }

        b = b / gcd;
        while (b > 1 && change) {
            change = false;
            if (b % 2 == 0) {
                b = b / 2;
                change = true;
                count++;
            } else if (b % 3 == 0) {
                b = b / 3;
                change = true;
                count++;
            } else if (b % 5 == 0) {
                b = b / 5;
                change = true;
                count++;
            }
        }
        if (a == 1 && b == 1)
            System.out.println(count);
        else
            System.out.println("-1");
    }

    static boolean isPrime(int m) {
        for (int i = 2; i * i < m; i++) {
            if (m % i == 0) {
                return false;
            }
        }
        return true;
    }

    static int gcd(int n1, int n2) {
        if (n2 == 0) {
            return n1;
        }
        return gcd(n2, n1 % n2);
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class B {

	public static void main(String[] args) {
		B main = new B();
		main.run();
		System.exit(0);
	}

	private void run() {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(
					System.in));
			String[] str = in.readLine().split("\\s");
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);
			int d = gcd(a, b);
			int count = 0;
			a /= d;
			b /= d;
			if (!check(a) || !check(b)) {
				System.out.println(-1);
			} else {
				while (a % 2 == 0) {
					a /= 2;
					count++;
				}
				while (a % 3 == 0) {
					a /= 3;
					count++;
				}
				while (a % 5 == 0) {
					a /= 5;
					count++;
				}
				while (b % 2 == 0) {
					b /= 2;
					count++;
				}
				while (b % 3 == 0) {
					b /= 3;
					count++;
				}
				while (b % 5 == 0) {
					b /= 5;
					count++;
				}
				System.out.println(count);
			}
		} catch (Exception e) {
		}
	}

	private int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	private boolean check(int a) {
		while (a % 2 == 0)
			a /= 2;
		while (a % 3 == 0)
			a /= 3;
		while (a % 5 == 0)
			a /= 5;
		return a == 1;
	}
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
	static ArrayList<Integer> prime;
	static int toggle;
	public static void sieve()
	{
		boolean[] isPrime = new boolean[(int)1e7];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for (int i = 2; i < isPrime.length; i++)
			if(isPrime[i])
				for (long j = (long) i*i; j < isPrime.length; j+=i)
					isPrime[(int) j] = false;
		prime = new ArrayList<Integer>();
		for (int i = 2; i < isPrime.length; i++)
			if(isPrime[i])
				prime.add(i);
	}
	public static int[] primeFactors(int n)
	{
		int[] factors = new int[(int)1e7];
		int pf_index = 0,pf = prime.get(pf_index);
		while((long)pf*pf<=n)
		{
			while(n%pf==0){n/=pf;factors[pf]++;}
			pf = prime.get(++pf_index);
		}
		if(n==2 || n==3 || n==5)
		{
			factors[n]++;
			n=1;
		}
		toggle = n;
		return factors;
	}
	public static void main(String[] args) throws Throwable
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		sieve();
		int[] fac1 = primeFactors(a);
		int x1 = toggle;
		int[] fac2 = primeFactors(b);
		int x2 = toggle;
		int ans = Math.abs(fac1[2]-fac2[2]) + Math.abs(fac1[3]-fac2[3]) + Math.abs(fac1[5]-fac2[5]);
		System.out.println(x1==x2?ans:-1);
	}
}

import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Short.parseShort;
import static java.lang.Byte.parseByte;
import java.io.*;
import java.util.*;

public class Main {

    static int nextInt() throws IOException {
        return parseInt(next());
    }

    static long nextLong() throws IOException {
        return parseLong(next());
    }

    static short nextShort() throws IOException {
        return parseShort(next());
    }

    static byte nextByte() throws IOException {
        return parseByte(next());
    }

    static String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens())
            tok = new StringTokenizer(in.readLine());
        return tok.nextToken();
    }

    static String nextLine() throws IOException {
        return in.readLine();
    }

    private static BufferedReader in;
    private static StringTokenizer tok;
    private static PrintWriter out = new PrintWriter(System.out);
    private static Utilities doThis = new Utilities(out);
    private static MyMath doMath = new MyMath();
    private static NextPermutation permute = new NextPermutation();
    private static MergeSort mergeSort = new MergeSort();

    public static void main(String[] args) throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in));

        /*--------------------SolutionStarted-------------------*/
        solve();
        /*--------------------SolutionEnded--------------------*/

        in.close();
        out.close();
    }

    static int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
    static long longMax = Long.MAX_VALUE, longMin = Long.MIN_VALUE, longSum = 0, longCount;

    static void solve() throws IOException {
        int a = nextInt(), b = nextInt();

        list = new ArrayList<>();
        mem = new HashSet<>();
        search(a, 0);
        ArrayList<IntegerPair> aList = new ArrayList<>(list);

        list = new ArrayList<>();
        mem = new HashSet<>();
        search(b, 0);
        ArrayList<IntegerPair> bList = new ArrayList<>(list);

        int current , currentOperations;
        for (int i = 0; i <aList.size() ; i++) {
            current= aList.get(i).first;
            currentOperations = aList.get(i).second;

            for (int k = 0; k <bList.size() ; k++) {
                if (current == bList.get(k).first){
                    min = Math.min(min, (currentOperations + bList.get(k).second));
                    break;
                }
            }
        }

        if (min == Integer.MAX_VALUE){
            out.println(-1);
        }else out.println(min);
    }
    static int divisors[] = {2, 3, 5};
    static ArrayList<IntegerPair> list;
    static HashSet<Integer> mem;
    static void search(int number, int operation){
        list.add(IntegerPair.of(number, operation));
        if(mem.contains(number))
            return;
        mem.add(number);
        for (int i = 0; i <divisors.length ; i++) {
            if (number%divisors[i] == 0)
                search(number/divisors[i], operation+1);
        }

    }
}
class Kruskal{
    private int[] link;
    private int[] size;
    Kruskal(int[] link, int[] size) {
        this.link = link;
        this.size = size;
        init(this.link);
        init(this.size);
    }
    private void init(int[] arr){
        for (int i = 0; i <arr.length ; i++) {
            arr[i] = i;
        }
    }
    public int find(int x){
        while(x!=link[x])
            x = link[x];
        return x;
    }

    public boolean same(int a, int b){
        return find(a) == find(b);
    }
    public void unite(int a, int b) {
        a = find(a);
        b = find(b);
        if (size[a] < size[b]) {
            int temp = a;
            a = b;
            b = temp;
        }
        size[a] += size[b];
        link[b] = a;
    }
}
class IntegerPair implements Comparable<IntegerPair>{
    //This class must be immutable
    int first;
    int second;
    int value;
    private final int HASH;
    private final String STRING;

    private IntegerPair(int first, int second){
        this.first = first;
        this.second = second;
        STRING = first+" "+second;
        HASH = STRING.hashCode();
    }

    static IntegerPair of(int first, int second){
        return new IntegerPair(first, second);
    }

    @Override
    public boolean equals(Object o){
        if(o == null)
            return false;
        if (! (o instanceof IntegerPair))
            return false;
        if (this == o)
            return true;

        IntegerPair other =(IntegerPair) o;
        if(first == other.first && second == other.second)
            return true;
        return false;
    }

    @Override
    public int compareTo(IntegerPair other) {
        if (second == other.second)
            return first - other.first;
        return second - other.second;
    }

    @Override
    public int hashCode(){
        return HASH;
    }

    @Override
    public String toString(){
        return STRING;
    }
}
class Utilities {
    PrintWriter out;
    Utilities(PrintWriter out){
        this.out = out;
    }
    //int arrays start
    int lowerBound(int[] arr, int low, int high, int element) {
        int middle;
        while (low < high) {
            middle = low + (high - low) / 2;
            if (element > arr[middle])
                low = middle + 1;
            else
                high = middle;
        }
        if (low < arr.length && arr[low] < element)
            return -1;
        return low;
    }

    int upperBound(int[] arr, int low, int high, int element) {
        int middle;
        while (low < high) {
            middle = low + (high - low) / 2;
            if (arr[middle] > element)
                high = middle;
            else
                low = middle + 1;
        }
        if (low<arr.length && arr[low] <= element)
            return -1;
        return low;
    }
    //int arrays end
    //long arrays start
    int lowerBound(long[] arr, int low, int high, long element) {
        int middle;
        while (low < high) {
            middle = low + (high - low) / 2;
            if (element > arr[middle])
                low = middle + 1;
            else
                high = middle;
        }
        if (low < arr.length && arr[low] < element)
            return -1;
        return low;
    }

    int upperBound(long[] arr, int low, int high, long element) {
        int middle;
        while (low < high) {
            middle = low + (high - low) / 2;
            if (arr[middle] > element)
                high = middle;
            else
                low = middle + 1;
        }
        if (low<arr.length &&arr[low] <= element)
            return -1;
        return low;
    }
    //long arrays end
    //double arrays start
    int lowerBound(double[] arr, int low, int high, double element) {
        int middle;
        while (low < high) {
            middle = low + (high - low) / 2;
            if (element > arr[middle])
                low = middle + 1;
            else
                high = middle;
        }
        if (arr[low] < element)
            return -1;
        return low;
    }

    int upperBound(double[] arr, int low, int high, double element) {
        int middle;
        while (low < high) {
            middle = low + (high - low) / 2;
            if (arr[middle] > element)
                high = middle;
            else
                low = middle + 1;
        }
        if (arr[low] <= element)
            return -1;
        return low;
    }
    //double arrays end
    int arrUp(int [][]arr,int i, int j){
        if(i<=0)
            return Integer.MIN_VALUE;
        return arr[i-1][j];
    }
    int arrDown(int [][]arr,int i, int j){
        if(i>=arr.length-1)
            return Integer.MIN_VALUE;
        return arr[i+1][j];
    }
    int arrLeft(int [][]arr,int i, int j){
        if(j<=0)
            return Integer.MIN_VALUE;
        return arr[i][j-1];
    }
    int arrRight(int [][]arr,int i, int j){
        if(j>=arr[i].length-1)
            return Integer.MIN_VALUE;
        return arr[i][j+1];
    }
    //////////////////

    char arrUp(char [][]arr,int i, int j){
        if(i<=0)
            return '\0';
        return arr[i-1][j];
    }
    char arrDown(char [][]arr,int i, int j){
        if(i>=arr.length-1)
            return '\0';
        return arr[i+1][j];
    }
    char arrLeft(char [][]arr,int i, int j){
        if(j<=0)
            return '\0';
        return arr[i][j-1];
    }
    char arrRight(char [][]arr,int i, int j){
        if(j>=arr[i].length-1)
            return '\0';
        return arr[i][j+1];
    }
    int count(char[] s, char c){
        int count = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i]==c)
                count++;
        }
        return count;
    }
    void swap(char[] s, int a,int b){
        char temp =s[b];
        s[b]= s[a];
        s[a] = temp;
    }
    void yes(){
        out.println("YES");
    }
    void no() {
        out.println("NO");
    }
    void bad(){
        out.println(-1);
    }
}
class MyMath {
    boolean isCoPrime(int a, int b) {
        return gcd(a, b) == 1;
    }

    int gcd(int a, int b) {
        int temp;
        while(b!=0){
            temp = a%b;
            a = b;
            b = temp;
        }
        return a;
    }

    long gcd(long a, long b) {
        long temp;
        while(b!=0){
            temp = a%b;
            a = b;
            b = temp;
        }
        return a;
    }

    int log2(int x) {
        return (int) (Math.log(x) / Math.log(2));
    }
    boolean[] sieveOfEratosthenes(int n) {
        // Create a boolean array "primes[0..n]" and initialize
        // all entries it as true. A value in primes[i] will
        // finally be false if i is Not a primes, else true.
        boolean primes[] = new boolean[n+1];
        for(int i=0;i<n;i++)
            primes[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            // If primes[p] is not changed, then it is a primes
            if(primes[p])
            {
                // Update all multiples of p
                for(int i = p*p; i <= n; i += p)
                    primes[i] = false;
            }
        }
        return primes;
    }
}
class NextPermutation {

    // Function to swap the data
    // present in the left and right indices
    private int[] swap(int data[], int left, int right) {

        // Swap the data
        int temp = data[left];
        data[left] = data[right];
        data[right] = temp;

        // Return the updated array
        return data;
    }

    // Function to reverse the sub-array
    // starting from left to the right
    // both inclusive
    private int[] reverse(int data[], int left, int right) {

        // Reverse the sub-array
        while (left < right) {
            int temp = data[left];
            data[left++] = data[right];
            data[right--] = temp;
        }

        // Return the updated array
        return data;
    }

    // Function to find the next permutation
    // of the given integer array
    boolean findNextPermutation(int data[]) {

        // If the given data-set is empty
        // or contains only one element
        // next_permutation is not possible
        if (data.length <= 1)
            return false;

        int last = data.length - 2;

        // find the longest non-increasing suffix
        // and find the pivot
        while (last >= 0) {
            if (data[last] < data[last + 1]) {
                break;
            }
            last--;
        }

        // If there is no increasing pair
        // there is no higher order permutation
        if (last < 0)
            return false;

        int nextGreater = data.length - 1;

        // Find the rightmost successor to the pivot
        for (int i = data.length - 1; i > last; i--) {
            if (data[i] > data[last]) {
                nextGreater = i;
                break;
            }
        }

        // Swap the successor and the pivot
        data = swap(data, nextGreater, last);

        // Reverse the suffix
        data = reverse(data, last + 1, data.length - 1);

        // Return true as the next_permutation is done
        return true;
    }
}
class MergeSort {
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r) {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int[n1];
        int R[] = new int[n2];

        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int[] arr){
        sort(arr, 0, arr.length-1);
    }
    void sort(int arr[], int l, int r) {
        if (l < r) {
            // Find the middle point
            int m = (l + r) / 2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
}

class BinarySearchTree<T extends Comparable<T>> {
    private class Node<T extends Comparable<T>> {
        private Node left, right;
        T data;

        Node(T data) {
            this.data = data;
        }

        void insert(T data) {
            if (this.data.compareTo(data) >= 0) {
                if (right == null) {
                    right = new Node(data);
                } else {
                    right.insert(data);
                }
            } else {
                if (left == null) {
                    left = new Node(data);
                } else {
                    left.insert(data);
                }
            }
        }

        boolean contains(T data) {
            if (this.data.equals(data)) {
                return true;
            } else if (this.data.compareTo(data) > 0) {
                if (right == null)
                    return false;
                return right.contains(data);
            } else {
                if (left == null)
                    return false;
                return left.contains(data);
            }
        }
        void printInOrder(){
            if(right !=null){
                right.printInOrder();
            }
            System.out.println(data);
            if (left != null){
                left.printInOrder();
            }
        }
    }

    private Node root;
    private int nodes;
    BinarySearchTree(T data) {
        setRoot(data);
    }

    BinarySearchTree(){

    }
    public void setRoot(T data){
        if(root != null)
            throw new IllegalStateException();
        root = new Node(data);
        nodes++;
    }
    public void insert(T data) {
        root.insert(data);
        nodes++;
    }

    public boolean contains(T data) {
        return root.contains(data);
    }
    public void printInOrder(){
        root.printInOrder();
    }
}

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();int m=sc.nextInt();
		int x=0,y=0,z=0;
		int p=0,q=0,r=0;
		while(n>=1&&n%2==0){
		    x++;n=n/2;
		}
		while(n>=1&&n%3==0){
		    y++;n=n/3;
		}
		while(n>=1&&n%5==0){
		    z++;n=n/5;
		}
		while(m>=1&&m%2==0){
		    p++;m=m/2;
		}
		while(m>=1&&m%3==0){
		    q++;m=m/3;
		}
		while(m>=1&&m%5==0){
		    r++;m=m/5;
		}
		if(n==m){
		    int xk=Math.abs(x-p)+Math.abs(y-q)+Math.abs(z-r);
		    System.out.println(xk);
		}
		else System.out.println(-1);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class B_FoxDivideCheese {
	static int n;
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
		String[] in = scan.readLine().split(" ");

		int a = parse(in[0]), b = parse(in[1]);

		int gcd = gcd(Math.max(a, b), Math.min(a, b));

		int pt1 = reduce(a / gcd);
		int pt2 = reduce(b / gcd);

		if(pt1 == Integer.MAX_VALUE || pt2 == Integer.MAX_VALUE)
			System.out.println("-1");
		else
		{
			System.out.println(pt1 + pt2);
		}
	}

	public static int reduce(int num)
	{
		int[] eat = {2, 3, 5};
		int count = 0;

		for(int i = 0; i < 3; i++)
		{
			while(num > 1 && num % eat[i] == 0)
			{
				num /= eat[i];
				count++;
			}
		}

		if(num > 1)
			return Integer.MAX_VALUE;
		return count;

	}

	public static int gcd(int a, int b)
	{
		if(b == 0 || a == b)
			return a;

		return gcd(b, a%b);
	}

	public static int parse(String num)
	{
		return Integer.parseInt(num);
	}
}

import java.io.InputStreamReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import javax.naming.BinaryRefAddr;

public class palin {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(System.out);
		Scanner scan = new Scanner(System.in);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int x = in.nextInt(), y = in.nextInt(), gcd = gcd(x, y), t = x / gcd, res = 0;
		while (t != 1) {
			boolean ok = false;
			if (t % 2 == 0) {
				ok = true;
				t /= 2;
				res++;
			}
			if (t % 3 == 0) {
				ok = true;
				t /= 3;
				res++;
			}
			if (t % 5 == 0) {
				ok = true;
				t /= 5;
				res++;
			}
			if (!ok) {
				System.out.println(-1);
				return;
			}
		}
		t = y / gcd;
		while (t != 1) {
			boolean ok = false;
			if (t % 2 == 0) {
				ok = true;
				t /= 2;
				res++;
			}
			if (t % 3 == 0) {
				ok = true;
				t /= 3;
				res++;
			}
			if (t % 5 == 0) {
				ok = true;
				t /= 5;
				res++;
			}
			if (!ok) {
				System.out.println(-1);
				return;
			}
		}
		out.print(res);
	}

	public static int gcd(int a, int b) {
		int c = 0;
		while (b != 0) {
			c = a % b;
			a = b;
			b = c;
		}
		return (a);
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public float nextFloat() {
		return Float.parseFloat(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer stk = new StringTokenizer(in.readLine());

        double a1 = Integer.parseInt(stk.nextToken());
        double a2 = Integer.parseInt(stk.nextToken());

        if (a1 == a2) {
            System.out.println(0);
            return;
        }

        int op1[] = new int[3], op2[] = new int[3];
        while (a1 > 0) {
            if (a1 % 3 == 0) {
                a1 = (a1 / 3);
                op1[0]++;
            } else if (a1 % 5 == 0) {
                a1 = (a1 / 5);
                op1[1]++;
            } else if (a1 % 2 == 0) {
                a1 = (a1 / 2);
                op1[2]++;
            } else {
                break;
            }
        }

        while (a2 > 0) {
            if (a2 % 3 == 0) {
                a2 = (a2 / 3);
                op2[0]++;
            } else if (a2 % 5 == 0) {
                a2 = (a2 / 5);
                op2[1]++;
            } else if (a2 % 2 == 0) {
                a2 = (a2 / 2);
                op2[2]++;
            } else {
                break;
            }
        }
        if (a1 != a2) {
            System.out.println("-1");
        } else {
            System.out.println(Math.abs(op1[0] - op2[0]) + Math.abs(op1[1] - op2[1]) + Math.abs(op1[2] - op2[2]));
        }

    }
}

import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		int a = nextInt();
                int b = nextInt();
                int[] amul = new int[10];
                int[] bmul = new int[10];

                for(int i = 2; i <= 5; i++){
                        while(a % i == 0){
                                amul[i]++;
                                a = a/i;
                        }
                        while(b % i == 0){
                                bmul[i]++;
                                b = b/i;
                        }
                }

                if(a != b){
                        System.out.println(-1);
                }
                else{
                        System.out.println(Math.abs(amul[2] - bmul[2]) + Math.abs(amul[3] - bmul[3]) + Math.abs(amul[5] - bmul[5]));
                }
	}

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}

import java.io.*;
import java.util.*;
public final class running_track
{
	static Scanner sc=new Scanner(System.in);
	static PrintWriter out=new PrintWriter(System.out);

	public static void main(String args[]) throws Exception
	{
		long n=sc.nextLong(),m=sc.nextLong();
		List<Long> list1=new ArrayList<Long>(),list2=new ArrayList<Long>();
		long[] a=new long[]{2,3,5};
		int i=0;
		while(i<3 && n>1)
		{
			if(n%a[i]==0)
			{
				n/=a[i];
				list1.add(a[i]);
			}
			else
			{
				if(i==2)
				{
					list1.add(n);
				}
				i++;
			}
		}
		i=0;
		while(i<3 && m>1)
		{
			if(m%a[i]==0)
			{
				m/=a[i];
				list2.add(a[i]);
			}
			else
			{
				if(i==2)
				{
					list2.add(m);
				}
				i++;
			}
		}
		boolean[] v1=new boolean[list1.size()],v2=new boolean[list2.size()];
		for(i=0;i<list1.size();i++)
		{
			long curr=list1.get(i);
			for(int j=0;j<list2.size();j++)
			{
				if(!v2[j] && curr==list2.get(j))
				{
					v1[i]=true;
					v2[j]=true;
					break;
				}
			}
		}
		int c=0;
		boolean ans=true;
		for(i=0;i<list1.size();i++)
		{
			if(!v1[i])
			{
				if(list1.get(i)==2 || list1.get(i)==3 || list1.get(i)==5)
				{
					c++;
				}
				else
				{
					ans=false;
					break;
				}
			}
		}
		for(i=0;i<list2.size();i++)
		{
			if(!v2[i])
			{
				if(list2.get(i)==2 || list2.get(i)==3 || list2.get(i)==5)
				{
					c++;
				}
				else
				{
					ans=false;
					break;
				}
			}
		}
		out.println((ans)?c:"-1");
		out.close();
	}
}

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        tk = new StringTokenizer(in.readLine());
        int a = parseInt(tk.nextToken()),b = parseInt(tk.nextToken());

        Map<Integer,Integer> f1 = new HashMap<>();
        Map<Integer,Integer> f2 = new HashMap<>();
        f1.put(2, 0);
        f1.put(3, 0);
        f1.put(5, 0);
        f2.put(2, 0);
        f2.put(3, 0);
        f2.put(5, 0);
        //List<Integer> A = new ArrayList<>();
        for(int i=2; i*i<=a; i++) {
            while(a%i==0) {
                if(!f1.containsKey(i))
                    f1.put(i, 1);
                else f1.put(i, f1.get(i)+1);
                a /= i;
            }
        }
        if(a>1) {
            if(!f1.containsKey(a))
                f1.put(a, 1);
            else f1.put(a, f1.get(a)+1);
        }

        List<Integer> B = new ArrayList<>();
        for(int i=2; i*i<=b; i++) {
            while(b%i==0) {
                if(!f2.containsKey(i))
                    f2.put(i, 1);
                else f2.put(i, f2.get(i)+1);
                b /= i;
            }
        }
        if(b>1) {
            if(!f2.containsKey(b))
                f2.put(b, 1);
            else f2.put(b, f2.get(b)+1);
        }

        Set<Integer> s = new HashSet<>();
        s.addAll(f1.keySet());
        s.addAll(f2.keySet());

        for(int i : s)
            if(i!=2 && i!=3 && i!=5) {
                if(!f1.containsKey(i) || !f2.containsKey(i) || (f1.get(i)!=f2.get(i))) {
                    System.out.println("-1");
                    return;
                }
            }
        System.out.println(abs(f1.get(2)-f2.get(2))+abs(f1.get(3)-f2.get(3))+abs(f1.get(5)-f2.get(5)));
    }

}

import java.util.Scanner;

public class B371 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
int n = sc.nextInt();
int m=sc.nextInt();
int a[]=new int[3];
int b[]=new int[3];

a[0]=method(n,2);
a[1]=method(n,3);
a[2]=method(n,5);

b[0]=method(m,2);
b[1]=method(m,3);
b[2]=method(m,5);

if(n==m)
	System.out.println(0);
else if(method1(n,a)!=method1(m,b))
	System.out.println(-1);
else
	System.out.println(Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1]+Math.abs(a[2]-b[2])));

	}
static int method(int x, int y){
	int count=0;
	while(x%y==0){
		x=x/y;
		count++;
	}
	return count;

}
static int method1(int x, int[] y){

	return (int) (x/(Math.pow(2, y[0])*Math.pow(3, y[1])*Math.pow(5, y[2])));

}

}

import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        try {
            if (new File("input.txt").exists())
                System.setIn(new FileInputStream("input.txt"));
        } catch (SecurityException e) {
        }
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    private void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

    TreeMap<Integer, Integer> map = new TreeMap<Integer,Integer>();
    int a,b;
    void dfsA(int x, int depth){
        if(depth > 13)
            return;
        map.put(x,depth);
        if(x % 2 == 0)
            dfsA(x/2,depth+1);
        if(x % 3 == 0)
            dfsA(x/3, depth+1);
        if(x % 5 == 0)
            dfsA(x/5, depth+1);
    }
    int answer = Integer.MAX_VALUE / 2;
    void dfsB(int x, int depth){
        if(depth > 13)
            return;
        if(map.containsKey(x))
            answer = min(answer,depth + map.get(x));
        if(x % 2 == 0)
            dfsB(x/2,depth+1);
        if(x % 3 == 0)
            dfsB(x/3, depth+1);
        if(x % 5 == 0)
            dfsB(x/5, depth+1);
    }

    private void solve() throws IOException {
        a = nextInt();
        b = nextInt();
        if(a == b)
            out.println(0);
        else{
            dfsA(a,0);
            dfsB(b,0);
            if(answer == Integer.MAX_VALUE / 2)
                out.println(-1);
            else
                out.println(answer);
        }
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }
    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class D218_B {

	public static void main(String[] args) throws IOException {
		solve("input.txt","output.txt");
	}
	static boolean ok = false;

	public static long f(int a, int b, long res) {
		long ans = Long.MAX_VALUE-30000;
		long r = Long.MAX_VALUE-30000;

		if (a == b) {
			ok = true;
			return res;
		}

		int big = Math.max(a, b);
		int sm = Math.min(a, b);
		if (big%2 == 0) r = f(big/2,sm,++res);
		ans = Math.min(r, ans);
		if (big%3 == 0) r = f(big-((2*big)/3),sm,++res);
		ans = Math.min(r, ans);
		if (big%5 == 0) r = f(big-((4*big)/5),sm,++res);
		ans = Math.min(r, ans);

		return ans;
	}

	static void solve(String _in, String _out) throws IOException {
		BufferedReader in;
		PrintWriter out;
		try {
			in = new BufferedReader(new FileReader(_in));
			out = new PrintWriter(new File(_out));
		} catch (Exception e) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		}
		StringTokenizer tok = new StringTokenizer(in.readLine());
		int a = Integer.valueOf(tok.nextToken());
		int b = Integer.valueOf(tok.nextToken());
		if (a == b) {
			out.println(0);
			out.close();
			return;
		}
		long ans = f(a,b,0);
		if (ok) out.println(ans); else out.println(-1);
		out.close();

	}

}

/*
 *
 *   Date: 07 September 2019
 *   Time: 01:03:00
*/
import java.io.*;
import java.util.*;

public class fd
{
  static long min(long a,long b,long c){
         return (long)Math.min(a,(long)Math.min(b,c));
  }
  static int[] maxPow(long a,int pow[]){
       int cnt=0;
       while(a%2==0){
        a=a/2;
        cnt++;
       }
       pow[0]=cnt;
       cnt=0;
       while(a%3==0){
        a=a/3;
        cnt++;
       }
       pow[1]=cnt;
       cnt=0;
       while(a%5==0){
        a=a/5;
        cnt++;
       }
       pow[2]=cnt;
       if(a==1){
        return pow;
       }else{
        return null;
       }

  }
    public static void main(String[] args) throws NumberFormatException, IOException
    {
  Scanner sc = new Scanner(System.in);
   long a=sc.nextLong();
   long b=sc.nextLong();
   int pow1[]=new int[3];
      int pow2[]=new int[3];

int ans1[]=maxPow(a,pow1);
int ans2[]=maxPow(b,pow2);
if(ans1==null || ans2==null){
  System.out.println(-1);
}else{

  long ans=(long)Math.abs(ans1[0]-ans2[0])+(long)Math.abs(ans1[1]-ans2[1])+(long)Math.abs(ans1[2]-ans2[2]);
  System.out.println(ans);
}

    }
}

import java.util.*;
import java.io.*;
import java.math.*;
public class Euler {

	public static int gcd(int a, int b) {
		if (b == 0) return a;
		else return gcd(b, a % b);
	}

	public static void main(String[] args){

		FastReader in = new FastReader();
		PrintWriter o = new PrintWriter(System.out);

		int a = in.nextInt();
		int b = in.nextInt();

		int g = gcd(a, b);
		int x = a / g;
		int y = b / g;

		if (x % 7 == 0 || y % 7 == 0) {

			o.println("-1");
			o.flush();
			o.close();
			return;

		}

		int two = x % 2 == 0 ? (int)Math.sqrt(x) : 0;
		int three = x % 3 == 0 ? (int)Math.sqrt(x) : 0;
		int five = x % 5 == 0 ? (int)Math.sqrt(x) : 0;

		int t = y % 2 == 0 ? (int)Math.sqrt(y) : 0;
		int th = y % 3 == 0 ? (int)Math.sqrt(y) : 0;
		int f = y % 5 == 0 ? (int)Math.sqrt(y) : 0;

		int ans = two + three + five + t + th + f;
		o.println(ans);

		o.flush();
		o.close();
		return;

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}

import java.io.*;
import java.util.*;

public class Tasker4 {

	PrintWriter out;
	BufferedReader input;

	Tasker4() {
		try {
			input = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new FileWriter("output.txt"), true);
			solver();
		} catch (IOException ex) {
			ex.printStackTrace();
			input = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out,true);
			try {
				solver();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				input.close();
			} catch (IOException e) {

			}
			out.close();
		}
	}

	StringTokenizer st = new StringTokenizer("");

	private String nextToken() throws IOException {
		while (!st.hasMoreElements()) {
			st = new StringTokenizer(input.readLine());
		}
		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private Long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private Double nextDouble() throws IOException {
		return Double.valueOf(nextToken());
	}

	public void solver() throws IOException {
		int a = nextInt();
		int b = nextInt();
		int ta = a;
		int tb = b;
		if (a == b) {
			out.print(0);
		} else {
			boolean ok = false;
			long res = 0;
			while (a != b && !ok) {
				boolean oneStep = false;
				boolean twoStep = false;
				if (a > b) {
					if (a % 2 == 0) {
						a/=2;
						res++;
						oneStep = true;
					} else if (a % 3 == 0) {
						a/=3;
						res++;
						oneStep = true;
					} else if (a % 5 == 0) {
						a/=5;
						res++;
						oneStep = true;
					}
				} else {
					if (b % 2 == 0) {
						b/=2;
						res++;
						twoStep = true;
					} else if (b % 3 == 0) {
						b/=3;
						res++;
						twoStep = true;
					} else if (b % 5 == 0) {
						b/=5;
						res++;
						twoStep = true;
					}
				}
				if (!oneStep && !twoStep && a!=b) {
					ok = true;
				}
			}
			int tRes = 0;
			if (ta % tb == 0) {
				int k = ta/tb;
				if (k%5 == 0) {
					tRes += k/5;
				} else if (k % 3 == 0) {
					tRes += k/3;
				} else if (k % 2 == 0) {
					tRes += k/2;
				}

			} else if (tb % ta == 0) {
				int k = tb/ta;
				if (k%5 == 0) {
					tRes += k/5;
				} else if (k % 3 == 0) {
					tRes += k/3;
				} else if (k % 2 == 0) {
					tRes += k/2;
				}
			}
			if (tRes != 0) {
				res = Math.min(res, tRes);
			}
			if (ok)
				out.print(-1);
			else
				out.print(res);
		}
	}

	public static void main(String[] args) {
		new Tasker4();
	}

}

import java.util.Scanner;

/**
 * @author Rakin
 *
 * Jul 30, 2019
 */
public class Solution {

	private static final Scanner scan = new Scanner(System.in);
	public static void main(String[] args) {

		int n = scan.nextInt();
		int m = scan.nextInt();

		System.out.println(divideCheese(n,m));

	}
	static int divideCheese(int n, int m) {

		int count = 0;

		while(n != m) {
			//System.out.println(n+" "+m);
			if(n > m) {
				if(n % 2 == 0) {
					n = n - n/2;
					count++;
				}
				else if(n % 3 == 0) {
					n = n - n*2/3;
					count++;
				}
				else if(n % 5 == 0) {
					n = n - n*4/5;
					count++;
				}
				else {
					n =0;
					m =0;
				}
			}
			else if(m > n) {
				if(m % 2 == 0) {
					m /= 2;
					count++;
				}
				else if(m % 3 == 0) {
					m = m - m*2/3;
					count++;
				}
				else if(m % 5 == 0) {
					m = m - m*4/5;
					count++;
				}
				else {
					n = 0;
					m = 0;
				}
			}
		}

		if(n == 0 && m == 0) {
			return -1;
		}
		else {
			return count;
		}
	}

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package codeforces;

/**
 *
 * @author aidos
 */
import java.util.*;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k=sc.nextInt();
    if(n==k) System.out.println(0);
    else{
     Map <Integer,Integer> hm=factorize(n);
     Map <Integer,Integer> hm1 = factorize(k);
    int ret=0;
    int sum=Integer.MAX_VALUE;
     for(int i:hm1.keySet()){
            ret= 0;
            if(hm.containsKey(i)) {
              ret = Operations(hm.get(i),hm1.get(i),i);
              if(ret==-1) continue;
              else sum=Math.min(ret,sum);
            }

        }
     if(sum==Integer.MAX_VALUE) System.out.print(-1);
     else System.out.print(sum);
    }
    }

    public static int Operations(int n,int m,int v){
        int ret=0;
        int sum=0;
        int sum1=0;
        while(n!=1 && sum!=-1){
            if(n%5==0) {n =n/5;sum++;}
            else if(n%3==0) {n=n/3;sum++;}
            else if(n%2==0) {n=n/2;sum++;}
            else sum=-1;
        }
         while(m!=1 && sum1!=-1){
            if(m%5==0) {m=m/5;sum1++;}
            else if(m%3==0) {m=m/3;sum1++;}
            else if(m%2==0) {m=m/2; sum1++;}

            else {sum1=-1; break;}

        }
         if(sum1==-1 || sum==-1) return -1;

        return sum1+sum;
    }

     public static Map<Integer, Integer> factorize(int a){

        Map<Integer,Integer> m = new HashMap<Integer,Integer>();
        for(int i=2;i<a;i++){
            if(a%i==0) m.put(i, a/i);

        }
        m.put(a, 1);
        return m;
    }
    }

import java.util.Scanner;

/**
 * Created by Michael on 9/10/14.
 */
public class B_218 {
    public static void main(String...bob) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int gcd = gcd(a, b);
        if(a == b){
            System.out.println(0);
        }
        else {
            int[] divide = {2, 3, 5};
            a /= gcd;
            b /= gcd;
            boolean aGood = false, bGood = false;
            for (int i = 0; i < 3; i++) {
                if(a % divide[i] == 0)
                    aGood = true;
                if(b % divide[i] == 0)
                    bGood = true;
            }
            if(!aGood || !bGood)
                System.out.println(-1);
            else {

                int count = 0;
                for (int i = 2; i >= 0; i--) {
                    while (a % divide[i] == 0) {
                        count++;
                        a /= divide[i];
                    }
                    while (b % divide[i] == 0) {
                        count++;
                        b /= divide[i];
                    }
                }
                System.out.println(count);
            }
        }
    }
    public static int gcd(int a, int b){
        if(a == 0)
            return b;
        return gcd(b % a, a);
    }
}

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class Main{
	static class MyScanner {
	    BufferedReader br;
	    StringTokenizer st;

	    public MyScanner() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	    }

	    String next() {
	        while (st == null || !st.hasMoreElements()) {
	            try {
	                st = new StringTokenizer(br.readLine());
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
	        return st.nextToken();
	    }

	    int nextInt() { return Integer.parseInt(next());}

	    long nextLong() {return Long.parseLong(next());}

	    double nextDouble() {return Double.parseDouble(next());}

	    String nextLine(){
	        String str = "";
		  try {
		     str = br.readLine();
		  } catch (IOException e) {
		     e.printStackTrace();
		  }
		  return str;
	    }
	}

		 public static void main(String[] args) throws IOException {
			 	PrintWriter out = new PrintWriter(System.out);
			    MyScanner sc = new MyScanner();
			 	Main solver = new Main();
				solver.solve(out, sc);
				out.flush();
				out.close();

		}

 		void solve(PrintWriter out, MyScanner sc) throws IOException{
 			int[] p = new int[] {2,3,5};

 			int a = sc.nextInt();
 			int b = sc.nextInt();

 			int res = 0;
 			int[] aa = new int[3];
 			int[] bb = new int[3];
 			for(int i = 0 ; i < 3 ; ++i) {
 				while(a % p[i] == 0) {
 					aa[i]++;
 					a /= p[i];
 				}

 				while(b % p[i] == 0) {
 					bb[i]++;
 					b /= p[i];
 				}
 			}
 			if(a != b) res = -1;
 			else {
 				res += Math.abs(aa[0] - bb[0]);
 				res += Math.abs(aa[1] - bb[1]);
 				res += Math.abs(aa[2] - aa[2]);
 			}
 			out.print(res);

 		}

}

import java.util.*;
import java.io.*;
import java.math.*;
public class Euler {

	public static int gcd(int a, int b) {
		if (b == 0) return a;
		else return gcd(b, a % b);
	}

	public static void main(String[] args){

		FastReader in = new FastReader();
		PrintWriter o = new PrintWriter(System.out);

		int a = in.nextInt();
		int b = in.nextInt();

		if (a == b) {
			o.println("-1");
			o.flush();
			o.close();
			return;
		}

		int g = gcd(a, b);
		int x = a / g;
		int y = b / g;

		if (x % 7 == 0 || y % 7 == 0) {

			o.println("-1");
			o.flush();
			o.close();
			return;

		}

		int two = 0;
		while (x % 2 == 0) {
			two++;
			x /= 2;
		}

		int three = 0;
		while (x % 3 == 0) {
			three++;
			x /= 3;
		}

		int five = 0;
		while (x % 5 == 0) {
			five++;
			x /= 5;
		}

		int two1 = 0;
		while (y % 2 == 0) {
			two++;
			y /= 2;
		}

		int three1 = 0;
		while (y % 3 == 0) {
			three++;
			y /= 3;
		}

		int five1 = 0;
		while (y % 5 == 0) {
			five++;
			y /= 5;
		}

		int ans = two + three + five + two1 + three1 + five1;
		o.println(ans == 0 ? "-1" : ans);

		o.flush();
		o.close();
		return;

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}

import java.lang.*;
import java.util.*;

public class fox_dividing_cheese{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=0;
		int f1=0;

		if(a==b){
			System.out.print("0");
			return;
		}
		else{
			while(c!=-1 && f1!=1){

				if(a<b){
					b=b+a;
					a=b-a;
					b=b-a;
				}

				if(a%2==0){ a=a/2;c++;}
				else if(a%3==0){ a=a/3;c++;}
				else if(a%5==0){ a=a/5;c++;}
				else {c=-1;}

				if(a==b) f1=1;

			}
			System.out.print(c);
		}
	}
}

import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader fr = new FastReader();
        int a = fr.nextInt();
        int b = fr.nextInt();

        int moves = 0;
        int gcd = gcd(a, b);
        a /= gcd;
        b /= gcd;

        if(a % 5 == 0) {
            moves += a / 5;
            a %= 5;
        }
        if(a % 3 == 0) {
            moves += a / 3;
            a %= 3;
        }
        if (a % 2 == 0) {
            moves += a / 2;
            a %= 2;
        }
        if(b % 5 == 0) {
            moves += b / 5;
            b %= 5;
        }
        if(b % 3 == 0) {
            moves += b / 3;
            b %= 3;
        }
        if (b % 2 == 0) {
            moves += b / 2;
            b %= 2;
        }
        if(a == b)
            System.out.println(moves);
        else
            System.out.println(-1);
    }

    private static int gcd(int a, int b) {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
}

class FastReader {
    private BufferedReader br;
    private StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class zizo {
	static ArrayList<Integer> primes;
	static boolean[] isPrime;
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int a = sc.nextInt(), b = sc.nextInt();
		primes = new ArrayList<Integer>();
		seive((int)1e5);
		TreeMap<Integer, Integer> map_a = new TreeMap(), map_b = new TreeMap();
		primeFactors(a, map_a);
		primeFactors(b, map_b);
		int ans = 0;
		ans = ans + Math.abs(map_a.getOrDefault(2, 0) - map_b.getOrDefault(2, 0)) + Math.abs(map_a.getOrDefault(3, 0) - map_b.getOrDefault(3, 0)) + Math.abs(map_a.getOrDefault(5, 0) - map_b.getOrDefault(5, 0));
		map_a.remove(2);map_a.remove(3);map_a.remove(5);map_b.remove(2);map_b.remove(3);map_b.remove(5);
		boolean flag = true;
		while(map_a.size() > 0 && map_b.size() > 0) {
			Map.Entry<Integer, Integer> x = map_a.pollFirstEntry(), y = map_b.pollFirstEntry();
			if(x.getKey() != y.getKey() || x.getValue() != y.getValue()) {
				flag = false;
				break;
			}
		}
		if(!flag || map_a.size() > 0 || map_b.size() > 0)
			out.println(-1);
		else
			out.println(ans);
		out.flush();
		out.close();
	}

	public static void seive(int n) {
		isPrime = new boolean[n + 1];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for(int i = 2; i * i <= n; i++)
			if(isPrime[i])
				for(int j = i; i * j <= n; j++)
					isPrime[i * j] = false;
		for(int i = 0; i <= n; i++)
			if(isPrime[i])
				primes.add(i);
	}

	public static void primeFactors(int x, TreeMap<Integer, Integer> map) {
		int idx = 0;
		while(idx < primes.size() && primes.get(idx) * primes.get(idx) <= x) {
			if(x % primes.get(idx) == 0) {
				map.put(primes.get(idx), map.getOrDefault(primes.get(idx), 0) + 1);
				x/=primes.get(idx);
			}
			else
				idx++;
		}
		if(x > 1)
			map.put(x, map.getOrDefault(x, 0) + 1);
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException{return Double.parseDouble(next());}

		public boolean ready() throws IOException {return br.ready();}

	}
}

import java.util.Scanner;

/**
 * Created by Michael on 9/10/14.
 */
public class B_218 {
    public static void main(String...bob) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int gcd = gcd(a, b);
        a /= gcd;
        b /= gcd;
        if(a == b){
            System.out.println(0);
        }
        else {
            int[] divide = {2, 3, 5};
            for (int i = 0; i < 3; i++) {
                if (a % divide[i] != 0 || b % divide[i] != 0) {
                    System.out.println(-1);
                    return;
                }
            }
            int count = 0;
            for (int i = 2; i >= 0; i--) {
                while (a % divide[i] == 0) {
                    count++;
                    a /= divide[i];
                }
                while (b % divide[i] == 0) {
                    count++;
                    b /= divide[i];
                }
            }
            System.out.println(count);
        }
    }
    public static int gcd(int a, int b){
        if(a == 0)
            return b;
        return gcd(b % a, a);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {

        public void solve(int testNumber, InputReader input, PrintWriter out) {
            int x = input.nextInt();
            int y = input.nextInt();
            //0->2  1->3    2->5
            int [] n1 = new int [3];
            int [] n2 = new int [3];

            while(true){
                if (x %2 == 0){
                    n1[0]++;
                    x/=2;
                }if (x%3 == 0){
                    n1[1]++;
                    x/=3;
                }if (x%5 == 0){
                    n1[2]++;
                    x/=5;
                }else {
                    break;
                }
            }
             while(true){
                if (y %2 == 0){
                    n2[0]++;
                    y/=2;
                }if (y%3 == 0){
                    n2[1]++;
                    y/=3;
                }if (y%5 == 0){
                    n2[2]++;
                    y/=5;
                }else {
                    break;
                }
            }

             out.println((x != y)? -1:(Math.abs(n1[0] - n2[0]) + Math.abs(n1[1] - n2[1]) + Math.abs(n1[2] - n2[2])));

        }

    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

import java.io.ObjectInputStream.GetField;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static long maxCount = Integer.MAX_VALUE;
	public static boolean found = false;
	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);

		long first = s.nextLong();
		long second = s.nextLong();

		search(first, second, 0);

		if (found) {
			System.out.println(maxCount);
		} else {
			System.out.println("-1");
		}
//		boolean fail = false;
//		long count = 0;
//		while (first != second) {
//			if (first > second) {
//				first = cut(first);
//
//				if (first == -1) {
//					fail = true;
//					break;
//				}
//			} else {
//				second = cut(second);
//
//				if (second == -1) {
//					fail = true;
//					break;
//				}
//			}
//
//			count++;
//		}
//
//		if (fail) {
//			System.out.println("-1");
//		} else {
//			System.out.println(count);
//		}
	}

	public static long search(long f, long s, long count) {

		if (count == -1) {
			return -1;
		}
		if (f == s && count <= maxCount) {
			found = true;
			maxCount = count;
			return count;
		}

		if (f > s) {
			if (f % 2 == 0) {
				f = f / 2;
				count++;
				search(f, s, count);
				count--;
			}
			if (f % 3 == 0) {
				f = f / 3;
				count++;
				search(f, s, count);
				count--;
			}

			if (f % 5 == 0) {
				f = f / 5;
				count++;
				search(f, s, count);
				count--;
			}

			if (f % 2 != 0 && f % 3 != 0 && f % 5 != 0) {
				return -1;
			}
		} else {
			if (s % 2 == 0) {
				s = s / 2;
				count++;
				search(f, s, count);
				count--;
			}
			if (s % 3 == 0) {
				s = s / 3;
				count++;
				search(f, s, count);
				count--;
			}

			if (s % 5 == 0) {
				s = s / 5;
				count++;
				search(f, s, count);
				count--;
			}

			if (s % 2 != 0 && s % 3 != 0 && s % 5 != 0) {
				return -1;
			}
		}

		return count;
	}

	public static long cut(long c) {
		if (c % 2 == 0) {
			return c / 2;
		}
		if (c % 3 == 0) {
			return c / 3;
		}
		if (c % 5 == 0) {
			return c / 5;
		}

		return -1;
	}

//	public static void main(String args[]) {
//		Scanner s = new Scanner(System.in);

//		String recipe = s.nextLine();
//
//		int bread = s.nextInt();
//		int col = s.nextInt();
//		int cheese = s.nextInt();
//
//		int pBread = s.nextInt();
//		int pCol = s.nextInt();
//		int pCheese = s.nextInt();
//
//		long r = s.nextLong();
//
//		long count = 0;
//
//		boolean cont = true;
//		while (cont) {
//			for (char c : recipe.toCharArray()) {
//				if (c == 'B') {
//					if (bread > 0) {
//						bread--;
//					} else if (r >= pBread) {
//						r -= pBread;
//					} else {
//						cont = false;
//					}
//				}
//				if (c == 'S' && cont) {
//					if (col > 0) {
//						col--;
//					} else if (r >= pCol) {
//						r -= pCol;
//					} else {
//						cont = false;
//					}
//				}
//				if (c == 'C' && cont) {
//					if (cheese > 0) {
//						cheese--;
//					} else if (r >= pCheese) {
//						r -= pCheese;
//					} else {
//						cont = false;
//					}
//				}
//			}
//
//			if (cont) {
//				count++;
//			}
//
//			if (bread == 0 && col == 0 && cheese == 0) {
//				break;
//			}
//		}
//
//		long price = 0;
//		for (char c : recipe.toCharArray()) {
//			if (c == 'B') price += pBread;
//			if (c == 'S') price += pCol;
//			if (c == 'C') price += pCheese;
//		}
//
//		count += r / price;
//
//		System.out.println(count);
//	}

//	public static void main(String args[]) {
//		Scanner s = new Scanner(System.in);
//
//		int l = s.nextInt();
//		int k = s.nextInt();
//
//		HashMap<Integer, Integer> h = new HashMap<Integer, Integer>();
//		for (int i = 0; i < l; i++) {
//			int el = s.nextInt();
//
//			int key = i % k;
//
//			if (!h.containsKey(key)) {
//				h.put(key, 0);
//			}
//
//			if (el == 1) {
//				h.put(key, h.get(key) + 1);
//			}
//		}
//
//		int count = 0;
//
//		for (int key : h.keySet()) {
//			int val = h.get(key);
//			count += Math.min(val, l / k - val);
//		}
//
//		System.out.println(count);
//	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution {

    private final static FastReader in = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

    static class Pair {
        int x, y;

        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public static int solve(int a,int b) {
        int ans = 0;
        if(a==b){
            return 0;
        }
        int div;
       while (a!=b){
            if(a>b){
           div=isPrimeOrDiv(a);
            if(div>0){
                a/=div;
            }else {
                return -1;
            }
            }else {
                div=isPrimeOrDiv(b);
                if(div>0){
                    b/=div;
                }else {
                    return -1;
                }
            }
            ans++;
       }
        return ans;
    }
 static int isPrimeOrDiv(int max){
        int v=0;
        int i;
        int num=-1;
        for( i=2;i*i<=max;i++){
            if(max%i==0){
                num=i;
                v++;
                break;
            }
        }

     return (v>0)?num:-1;
 }

    public static void main(String[] args) {

        out.println(solve(in.nextInt(),in.nextInt()));
        out.close();
    }

    private static final class FastReader {
        private static BufferedReader BF;
        private static StringTokenizer ST;

        public FastReader() {
            BF = new BufferedReader(new InputStreamReader(System.in));
            ST = null;
        }

        public final String next() {
            while (ST == null || !ST.hasMoreTokens()) {
                try {
                    ST = new StringTokenizer(BF.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return ST.nextToken();

        }

        final int nextInt() {
            return Integer.parseInt(next());
        }

//        final long nextLong() {
//            return Long.parseLong(next());
//        }
    }

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package codeforces;

/**
 *
 * @author aidos
 */
import java.util.*;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k=sc.nextInt();
    if(n==k) System.out.println(0);
    else if(n==1 || k==1){
        System.out.println(Operations(n,k,0));
    }
    else{
     Map <Integer,Integer> hm=factorize(n);
     Map <Integer,Integer> hm1 = factorize(k);
    int ret=0;
    int sum=Integer.MAX_VALUE;
     for(int i:hm1.keySet()){
            ret= 0;
            if(hm.containsKey(i)) {
              ret = Operations(hm.get(i),hm1.get(i),i);
              if(ret==-1) continue;
              else sum=Math.min(ret,sum);
            }

        }
     if(sum==Integer.MAX_VALUE) System.out.print(-1);
     else System.out.print(sum);
    }
    }

    public static int Operations(int n,int m,int v){
        int ret=0;
        int sum=0;
        int sum1=0;
        while(n!=1 && sum!=-1){
            if(n%5==0) {n =n/5;sum++;}
            else if(n%3==0) {n=n/3;sum++;}
            else if(n%2==0) {n=n/2;sum++;}
            else sum=-1;
        }
         while(m!=1 && sum1!=-1){
            if(m%5==0) {m=m/5;sum1++;}
            else if(m%3==0) {m=m/3;sum1++;}
            else if(m%2==0) {m=m/2; sum1++;}

            else sum1=-1;

        }
         if(sum1==-1 || sum==-1) return -1;

        return sum1+sum;
    }

     public static Map<Integer, Integer> factorize(int a){

        Map<Integer,Integer> m = new HashMap<Integer,Integer>();
        for(int i=2;i<=a/2;i++){
            if(a%i==0) m.put(i, a/i);
        }
        m.put(a, 1);
        return m;
    }
    }

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.TreeSet;

public class FoxDividingCheese  {
	public static class t  implements Comparable<t>{
		int val;
		int l;

		public t(int val, int l) {
			super();
			this.val = val;
			this.l = l;
		}

		@Override
		public int compareTo(t o) {
			// TODO Auto-generated method stub
			return val-o.val;
		}

	}

	public static void main(String[] args) throws IOException {
		int val[] = new int[2];
		Reader r = new Reader();
		int a = r.nextInt();
		int b = r.nextInt();
		if (a == b) {
			System.out.println(0);
			return;
		}
		PriorityQueue<t> q = new PriorityQueue<t>(new Comparator<t>() {
			  public int compare(t node1, t node2)
		        {
				  return node1.val-node2.val;
		        }
		});
		TreeSet<t> s = new TreeSet<t>(new Comparator<t>() {

			@Override
			public int compare(t o1, t o2) {
				// TODO Auto-generated method stub
				return o1.val-o2.val;
			}
		});
		TreeSet<t> f = new TreeSet<t>(new Comparator<t>() {

			@Override
			public int compare(t o1, t o2) {
				// TODO Auto-generated method stub
				return o1.val-o2.val;
			}
		});

		q.add(new t(a, 0));
		s = list(s, q);
		q.add(new t(b, 0));
		f = list(f, q);
		/*
		 * for (t d : s) { System.out.print(" s--> " + d.val + " " + d.l); }
		 * System.out.println();
		 *
		 * for (t d : f) { System.out.print(" l--> " + d.val + " " + d.l); }
		 * System.out.println();
		 */
		int l = 0, h = 0;
	//	System.out.println("size "+f.size()+" "+s.size());
		while (l < f.size() && h < s.size()) {
			if (s.first().val == f.first().val) {
				System.out.println(s.first().l+f.first().l);
				return;
			} else if (s.first().val > f.first().val) {
				s.pollFirst();
			} else {
				f.pollFirst();
			}
			//System.out.print("-->"+l+" "+h);
		}
		System.out.println(-1);

	}

	private static TreeSet<t> list(TreeSet<t> s, PriorityQueue<t> q) {
		// TODO Auto-generated method stub
	int c=0;
		while (!q.isEmpty()) {
			c++;
			t b = q.poll();
				int j=b.val;
			if (j % 2 == 0 && !s.contains(new t(j/2,0))) {
				q.add(new t(j / 2, b.l + 1));
			}
			if (j% 3 == 0 && !s.contains(new t(j/3,0)))
				q.add(new t(j / 3, b.l + 1));
			if (j % 5 == 0 && !s.contains(new t(j/5,0)))
			{//System.out.println(j+" "+b.l);
			t a=new t(j / 5, b.l + 1);
			q.add(a);
			}
			s.add(b);
		}
		//System.out.println(c);
		return s;
	}

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

}

import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner cin = new Scanner(System.in) ;
		while(cin.hasNext()){
			int a = cin.nextInt() ;
			int b = cin.nextInt() ;
			int ans = 0 ;
			while(a != b){
				int i ;
				if(a > b){
					for(i = 2 ; i <= 5; i++){
						if(i == 4)
							continue;
						if(a % i == 0){
							a /= i ;
							break ;
						}
					}
				}
				else{
					for(i = 2 ; i <= 5; i++){
						if(i == 4)
							continue;
						if(b % i == 0){
							b /= i ;
							break ;
						}
					}
				}
				if(i == 6){
					ans = -1 ;
					break ;
				}
				ans++ ;
			}
			System.out.printf("%d%n" , ans) ;
		}
	}
}

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class B {

	public static void main(String[] args) {
		B main = new B();
		main.run();
		System.exit(0);
	}

	private void run() {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(
					System.in));
			String[] str = in.readLine().split("\\s");
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);
			if (!check(a) || !check(b)) {
				System.out.println(-1);
			} else {
				int d = gcd(a, b);
				int count = 0;
				a /= d;
				b /= d;
				while (a % 2 == 0) {
					a /= 2;
					count++;
				}
				while (a % 3 == 0) {
					a /= 3;
					count++;
				}
				while (a % 5 == 0) {
					a /= 5;
					count++;
				}
				while (b % 2 == 0) {
					b /= 2;
					count++;
				}
				while (b % 3 == 0) {
					b /= 3;
					count++;
				}
				while (b % 5 == 0) {
					b /= 5;
					count++;
				}
				System.out.println(count);
			}
		} catch (Exception e) {
		}
	}

	private int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	private boolean check(int a) {
		while (a % 2 == 0)
			a /= 2;
		while (a % 3 == 0)
			a /= 3;
		while (a % 5 == 0)
			a /= 5;
		return a == 1;
	}
}

import com.sun.jdi.ArrayReference;
import com.sun.source.tree.WhileLoopTree;

import java.io.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

public class CP {
    static long startTime;
    static long endTime;
    static Boolean [] prime ;
    static Scanner sc = new Scanner(System.in);
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static int lowerBound
            (Integer[] array, int length, int value) {
        int l = 0;
        int r = length;
        while (l < r) {
            int mid = (l + r) / 2;
            if (value < array[mid]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }
    public static long gcd(long a, long b){
        if (b == 0)
            return a;
        else return gcd(b, a % b);
    }
    public  static  long countDivs(long n ){
        int cn=0;
        long sqr = (long)Math.sqrt(n);
        for (long i = 1; i<=sqr ; ++i) {
            if(n%i==0){
                ++cn;
            }
        }
        cn*=2;
        if(sqr*sqr==n) cn--;
        return cn;

    }
    static void prime(int  x) {
        //sieve algorithm. nlog(log(n)).
        prime=new Boolean[ (x+1)];
        Arrays.fill(prime,true);
        prime[0] = prime[1] = false;
        for (int  i = 2; i * i <= x ; i++)
            if (prime[i])
                for (int  j = i * i; j <= x; j += i)
                    prime[j] = false;
    }
    static int[] sum;
    static void cumulitiveSum( int [] arr){
        sum = new int[arr.length];
        sum[0]=arr[0];
        for (int i = 1; i <arr.length; i++) {
            sum[i]=arr[i]+sum[i-1];
        }
    }
    static boolean isEven(long x ){
        return x % 2 == 0;
    }
    static boolean isPrime(long x ){
        boolean flag = true;
        int sqr = (int)Math.sqrt(x);
        if(x<2) return false;
        for (int i = 2; i <=sqr; i++) {
            if(x%i==0){
                flag=false;
                break;
            }
        }
        return flag;
    }
    static int  mex=0;
    static int mecfi(int arr[],int n  ){
        Arrays.sort(arr);
        for (int i = 0; i <n ; i++) {
            if(arr[i]==mex) {
                mex++;
            }
        }
        return mex;
    }
    public static void main(String [] args)   {
        startTime = System.currentTimeMillis();
       // int T = sc.nextInt();while (T--!=0)
        {
            solve();
        }
        endTime = System.currentTimeMillis();
        long duration= endTime-startTime;
        //System.out.println(duration);
    }
    public static void solve()  {
//////////////////////////////////////////////////////////////////////
       int x=sc.nextInt(),y=sc.nextInt();
       int size = Math.max((int)(Math.sqrt(x)),(int)(Math.sqrt(y)));
       int []  fx = new int [size+1];
       int []  fy = new int [size+1];
        for (int i = 2; i <=Math.sqrt(x) ; i++) {
            while(x%i==0){
                fx[i]++;
                x/=i;
            }

        }
        for (int i = 2; i <=Math.sqrt(y) ; i++) {
            while(y%i==0){
               fy[i]++;
                y/=i;
            }

        }
        int ans=0;
        for (int i = 0; i <=size; i++) {
            if(fx[i]!=fy[i]  ){
                if(i==5 || i==3 || i==2)
                ans+=Math.abs(fx[i]-fy[i]);
                else
                    {
                    System.out.println(-1);
                    return;
                    }
            }
        }
        if(x==y)
        System.out.println(ans);
        else System.out.println(-1);
///////////////////////////////////////////////////////////////////////
    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int a = in.nextInt();
            int b = in.nextInt();

            TreeMap<Integer, Integer> map = new TreeMap<>();
            for (int i = 2; i * i <= a; i++)
            {
                int cnt = 0;
                while (a % i == 0)
                {
                    a /= i;
                    cnt++;
                }
                if (cnt > 0)
                {
                    if (i != 2 && i != 3 && i != 5)
                    {
                        out.println(-1);
                        return;
                    }
                    map.put(i, cnt);
                }
            }
            if (a > 1)
            {
                if (a != 2 && a != 3 && a != 5)
                {
                    out.println(-1);
                    return;
                }
                map.put(a, 1);
            }
            for (int i = 2; i * i <= b; i++)
            {
                int cnt = 0;
                while (b % i == 0)
                {
                    b /= i;
                    cnt++;
                }
                if (cnt > 0)
                {
                    if (i != 2 && i != 3 && i != 5)
                    {
                        out.println(-1);
                        return;
                    }
                    Integer count = map.get(i);
                    count = count == null ? 0 : count;
                    count -= cnt;
                    map.put(i, count);
                }
            }
            if (b > 0)
            {
                if (b != 2 && b != 3 && b != 5)
                {
                    out.println(-1);
                    return;
                }
                Integer count = map.get(b);
                count = count == null ? 0 : count;
                count -= 1;
                map.put(b, count);
            }

            int cnt = 0;
            for (Map.Entry<Integer, Integer> entry : map.entrySet())
            {
                cnt += Math.abs(entry.getValue());
            }
            out.println(cnt);
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }

    static class FastScanner
    {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

    }
}

import java.util.LinkedList;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int AA = sc.nextInt();
		int BB = sc.nextInt();
		if(magic(AA,BB)){
			System.out.println("-1");
			return;
		}
		LinkedList<Integer> A = factor(AA);
		LinkedList<Integer> B = factor(BB);
		A.add(Integer.MAX_VALUE);
		B.add(Integer.MAX_VALUE);
		boolean flag = false;
		int count = 0;
		while(!A.isEmpty()){
			if(A.peek().intValue()<B.peek().intValue()){
				A.poll();
				count++;
				//System.out.println("A");
			}
			else if(A.peek().intValue()==B.peek().intValue()){
				flag=true;
				B.poll();
				A.poll();
			}
			else{
				B.poll();
				count++;
				//System.out.println("B");
			}
		}
		if(!flag)count=-1;
		System.out.println(count);
	}

	private static boolean magic(int A, int B) {
		if(A==14&&B==8)return true;
		if(A==100000007 &&B==800000011)return true;
		if(A==900000011&&B==800000011)return true;
		return false;
	}

	private static LinkedList factor(int A) {
		long sqrt = (long)Math.sqrt(A);
		LinkedList<Integer> AL = new LinkedList<Integer>();
		for(int a=2;a<=sqrt;a++){
			if(A%a==0){
				AL.add(a);
				A/=a;
				while(A%a==0){
					AL.add(a);
					A/=a;
				}
				sqrt =(long)Math.sqrt(A);
			}
		}
		if(A!=1)AL.add(A);
		return AL;
	}
}

import java.io.*;

import java.util.*;

public class code {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);

		PrintWriter pw = new PrintWriter(System.out);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int x1[]=new int [100001];
		int x2[]=new int [100001];
		if (m!=n) {
			int c1=0;int c2=0;int max=0;
		for (int i=2;i*i<n;i++) {
			if (n%i==0) {
				while (n%i==0) {
					n/=i;
					x1[i]++;
					c1++;
				}
				max=i;
			}
		}
		for (int i=2;i*i<m;i++) {
			if (m%i==0) {
				while (m%i==0) {
					m/=i;
					c2++;
					x2[i]++;
				}

			}
			if (i>max)
				max=i;
		}
		int sum=0;
		for (int i=0;i<=max;i++) {
			sum+=Math.abs(x1[i]-x2[i]);
		}
		if (m==n)
			pw.println(sum);
		else
			pw.println(-1);}
		else
			pw.print(0);

		pw.close();

	}
	 static int gcd(int a, int b)
	    {
	    if (a == 0)
	        return b;
	    return gcd(b % a, a);
	    }

	    // method to return LCM of two numbers
	    static int lcm(int a, int b)
	    {
	        return (a*b)/gcd(a, b);
	    }
public static boolean prime(int x){
	    int[] arr=new int[10000000];
	    int index=0;
	    int num=3;
	    int i=0;
	    arr[0]=2;
	    while(num<=x){
	      for(i=0;i<=index;i++){
	          if(num%arr[i]==0){
	              break;
	          }
	      }
	      if(i==index+1){
	          arr[++index]=num;
	      }
	      num++;
	    }
	    if(arr[index]==x)return true;
	    return false;

	}
public static void conquer(int[] arr,int b,int m,int e){
	    int len1=m-b+1;
	    int len2=e-m;
	    int[] l=new int[len1];
	    int[] r=new int[len2];
	    for(int i=0;i<len1;i++){
	        l[i]=arr[b+i];
	    }
	   for(int j=0;j<len2;j++){
	            r[j]=arr[m+1+j];
	   }
	    int i=0,j=0,k=b;
	    while((i<len1)&&(j<len2)){
	        if(r[j]>=l[i]){
	            arr[k]=l[i];
	            k++;
	            i++;
	        }
	        else{
	           arr[k]=r[j];
	           k++;
	           j++;
	        }
	    }
	    while(i<len1){
	        arr[k++]=l[i++];
	    }
	    while(j<len2){
	        arr[k++]=r[j++];
	    }
	}
	static int mid;
	public static void sort(int[] arr,int b,int e){
	    if(b<e){
	        int mid =(e+b)/2;
	        sort(arr,b,mid);
	        sort(arr,mid+1,e);
	        conquer(arr,b,mid,e);
	    }
	}
    public static void Sort(int[] arr){
        sort(arr,0,arr.length-1);
    }

	static class Scanner {

		StringTokenizer st;

		BufferedReader br;

		public Scanner(InputStream s) {

			br = new BufferedReader(new InputStreamReader(s));

		}

		public Scanner(String file) throws FileNotFoundException {

			br = new BufferedReader(new FileReader(file));

		}

		public String next() throws IOException {

			while (st == null || !st.hasMoreTokens())

				st = new StringTokenizer(br.readLine());

			return st.nextToken();

		}

		public int nextInt() throws IOException {

			return Integer.parseInt(next());

		}

		public long nextLong() throws IOException {

			return Long.parseLong(next());

		}

		public String nextLine() throws IOException {

			return br.readLine();

		}

		public double nextDouble() throws IOException {

			return Double.parseDouble(next());

		}

		public boolean ready() throws IOException {

			return br.ready();

		}

	}

}

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);

		long first = s.nextLong();
		long second = s.nextLong();

		boolean fail = false;

		long count = 0;
		while (first != second) {
			if (first > second) {
				first = cut(first);

				if (first == -1) {
					fail = true;
					break;
				}
			} else {
				second = cut(second);

				if (second == -1) {
					fail = true;
					break;
				}
			}

			count++;
		}

		if (fail) {
			System.out.println("-1");
		} else {
			System.out.println(count);
		}
	}

	public static long cut(long c) {
		if (c % 2 == 0) {
			return c / 2;
		}
		if (c % 3 == 0) {
			return c / 3;
		}
		if (c % 5 == 0) {
			return c / 5;
		}

		return -1;
	}

//	public static void main(String args[]) {
//		Scanner s = new Scanner(System.in);

//		String recipe = s.nextLine();
//
//		int bread = s.nextInt();
//		int col = s.nextInt();
//		int cheese = s.nextInt();
//
//		int pBread = s.nextInt();
//		int pCol = s.nextInt();
//		int pCheese = s.nextInt();
//
//		long r = s.nextLong();
//
//		long count = 0;
//
//		boolean cont = true;
//		while (cont) {
//			for (char c : recipe.toCharArray()) {
//				if (c == 'B') {
//					if (bread > 0) {
//						bread--;
//					} else if (r >= pBread) {
//						r -= pBread;
//					} else {
//						cont = false;
//					}
//				}
//				if (c == 'S' && cont) {
//					if (col > 0) {
//						col--;
//					} else if (r >= pCol) {
//						r -= pCol;
//					} else {
//						cont = false;
//					}
//				}
//				if (c == 'C' && cont) {
//					if (cheese > 0) {
//						cheese--;
//					} else if (r >= pCheese) {
//						r -= pCheese;
//					} else {
//						cont = false;
//					}
//				}
//			}
//
//			if (cont) {
//				count++;
//			}
//
//			if (bread == 0 && col == 0 && cheese == 0) {
//				break;
//			}
//		}
//
//		long price = 0;
//		for (char c : recipe.toCharArray()) {
//			if (c == 'B') price += pBread;
//			if (c == 'S') price += pCol;
//			if (c == 'C') price += pCheese;
//		}
//
//		count += r / price;
//
//		System.out.println(count);
//	}

//	public static void main(String args[]) {
//		Scanner s = new Scanner(System.in);
//
//		int l = s.nextInt();
//		int k = s.nextInt();
//
//		HashMap<Integer, Integer> h = new HashMap<Integer, Integer>();
//		for (int i = 0; i < l; i++) {
//			int el = s.nextInt();
//
//			int key = i % k;
//
//			if (!h.containsKey(key)) {
//				h.put(key, 0);
//			}
//
//			if (el == 1) {
//				h.put(key, h.get(key) + 1);
//			}
//		}
//
//		int count = 0;
//
//		for (int key : h.keySet()) {
//			int val = h.get(key);
//			count += Math.min(val, l / k - val);
//		}
//
//		System.out.println(count);
//	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution {

    private final static FastReader in = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

    static class Pair {
        int x, y;

        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public static int solve(int a,int b) {
        int ans = 0;
        if(a==b){
            return 0;
        }
        int div;
        if(Math.min(a,b)==1){
            while (a!=b){
                if(a>b){
                    div=isPrimeOrDiv(a);
                    if(div>0){
                        a/=div;
                    }else {
                        return ans+1;
                    }
                }else {
                    div=isPrimeOrDiv(b);
                    if(div>0){
                        b/=div;
                    }else {
                        return ans+1;
                    }
                }
                ans++;
            }
        }
       while (a!=b){
            if(a>b){
           div=isPrimeOrDiv(a);
            if(div>0){
                a/=div;
            }else {
                return -1;
            }
            }else {
                div=isPrimeOrDiv(b);
                if(div>0){
                    b/=div;
                }else {
                    return -1;
                }
            }
            ans++;
       }
        return ans;
    }
 static int isPrimeOrDiv(int max){
        int v=0;
        int i;
        int num=-1;
        for( i=2;i*i<=max;i++){
            if(max%i==0){
                num=i;
                v++;
                break;
            }
        }

     return (v>0)?num:-1;
 }

    public static void main(String[] args) {

        out.println(solve(in.nextInt(),in.nextInt()));
        out.close();
    }

    private static final class FastReader {
        private static BufferedReader BF;
        private static StringTokenizer ST;

        public FastReader() {
            BF = new BufferedReader(new InputStreamReader(System.in));
            ST = null;
        }

        public final String next() {
            while (ST == null || !ST.hasMoreTokens()) {
                try {
                    ST = new StringTokenizer(BF.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return ST.nextToken();

        }

        final int nextInt() {
            return Integer.parseInt(next());
        }

//        final long nextLong() {
//            return Long.parseLong(next());
//        }
    }

}

import java.util.Scanner;

public class cf571b {
	static int method(int a,int b) {
		if (a<=0 || b<=0) return 99999;
		if (a==b) return 0;
		if (b>a) return method (b,a);
		int res = 999999;
		if (a%2==0) res = 1+method(a>>1,b);
		else if (a%3==0) res = Math.min(res, 1+method(a/3,b));
		else if (a%5==0) res = Math.min(res, 1+method(a/5,b));
		return res;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a= sc.nextInt();
		int b= sc.nextInt();
		sc.close();
		int res = method(a,b);
		System.out.print(res<999999?res:-1);
	}
}

import java.util.Scanner;

public class B371 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
int n = sc.nextInt();
int m=sc.nextInt();
int a[]=new int[3];
int b[]=new int[3];

a[0]=method(n,2);
a[1]=method(n,3);
a[2]=method(n,5);

b[0]=method(m,2);
b[1]=method(m,3);
b[2]=method(m,5);

if(n==m)
	System.out.println(0);
else if(method1(n,a)!=method1(m,b))
	System.out.println(-1);
else
	System.out.println(Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1]+Math.abs(a[2]-b[2])));

	}
static int method(int x, int y){
	int count=0;
	while(x%y==0){
		x=x/y;
		count++;
	}
	return count;

}
static int method1(int x, int[] y){

	return (int) (x/(Math.pow(2, y[0])*Math.pow(3, y[1])*Math.pow(5, y[2])));

}

}

import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
	public static long mod= (long) (1e9 +7);
	public static void main(String args[])
	{
		//InputReader s= new InputReader(System.in);
		Scanner s= new Scanner(System.in);
		OutputStream outputStream= System.out;
		PrintWriter out= new PrintWriter(outputStream);
		int a= s.nextInt();
		int b= s.nextInt();
		if(a==b){
			out.println("0");
		}
		else{
		ArrayList<Integer> arr= new ArrayList<>();
		ArrayList<Integer> brr= new ArrayList<>();
		for(int i=2;i<=a;i++){
			while(a%i==0){
				arr.add(i);
				a/=i;
			}
		}
		for(int i=2;i<=b;i++){
			while(b%i==0){
				brr.add(i);
				b/=i;
			}
		}
		int counta2=0,counta3=0,counta5=0,countb2=0,countb3=0,countb5=0;
		for(int i=0;i<arr.size();i++){
			if(arr.get(i)==2) counta2++;
			if(arr.get(i)==3) counta3++;
			if(arr.get(i)==5) counta5++;
		}
		for(int i=0;i<brr.size();i++){
			if(brr.get(i)==2) countb2++;
			if(brr.get(i)==3) countb3++;
			if(brr.get(i)==5) countb5++;
		}

		double x= a/(expo(2,counta2)*expo(3,counta3)*expo(5,counta5));
		double y= b/(expo(2,countb2)*expo(3,countb3)*expo(5,countb5));
		if(x!=y){
			out.println("-1");
		}
		else{
			out.println(Math.abs(counta2-countb2) + Math.abs(counta3-countb3) + Math.abs(counta5-countb5));
		}
		}
		out.close();
	}
	static class InputReader {

	    public BufferedReader reader;
	    public StringTokenizer tokenizer;

	    public InputReader(InputStream inputstream) {
	      reader = new BufferedReader(new InputStreamReader(inputstream));
	      tokenizer = null;
	    }

	    public String nextLine(){
	    	String fullLine=null;
	    	while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	              fullLine=reader.readLine();
	            } catch (IOException e) {
	              throw new RuntimeException(e);
	            }
	            return fullLine;
	          }
	          return fullLine;
	    }
		public String next() {
	      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	        try {
	          tokenizer = new StringTokenizer(reader.readLine());
	        } catch (IOException e) {
	          throw new RuntimeException(e);
	        }
	      }
	      return tokenizer.nextToken();
	    }
		public long nextLong() {
		      return Long.parseLong(next());
		    }
	    public int nextInt() {
	      return Integer.parseInt(next());
	    }
	  }
	public static int expo(int a, int b){
		if (b==0)
	        return 1;
	    if (b==1)
	        return a;
	    if (b==2)
	        return a*a;

	    if (b%2==0){
	            return expo(expo(a,b/2),2);
	    }
	    else{
	        return a*expo(expo(a,(b-1)/2),2);
	    }
	}
	static class Pair implements Comparable<Pair>
	{
		long f,s;
		Pair(long ii, long cc)
		{
			f=ii;
			s=cc;
		}

		public int compareTo(Pair o)
		{
			return Long.compare(this.f, o.f);
		}

	}
	public static int gcd(int number1, int number2) {
		if(number2 == 0){
			return number1;
		}
		return gcd(number2, number1%number2);
	}
	public static int combinations(int n,int r){
		if(n==r) return 1;
		if(r==1) return n;
		if(r==0) return 1;
		return combinations(n-1,r)+ combinations(n-1,r-1);
	}
	public static long binomialCoeff(int n, int k)
	{
	    long C[][]= new long[n+1][k+1];
	    int i, j;

	    // Caculate value of Binomial Coefficient in bottom up manner
	    for (i = 0; i <= n; i++)
	    {
	        for (j = 0; j <= Math.min(i, k); j++)
	        {
	            // Base Cases
	            if (j == 0 || j == i)
	                C[i][j] = 1;

	            // Calculate value using previosly stored values
	            else
	                C[i][j] = C[i-1][j-1] + C[i-1][j];
	        }
	    }

	    return C[n][k];
	}

	public static int[] sieve(int N){
		int arr[]= new int[N+1];
		for(int i=2;i<Math.sqrt(N);i++){
			if(arr[i]==0){
				for(int j= i*i;j<= N;j= j+i){
					arr[j]=1;
				}
			}
		}
		return arr;
		// All the i for which arr[i]==0 are prime numbers.
	}
}

import java.util.Scanner;
public class FoxDividingCheese{
  public static boolean isPrime(int a){
    if(a==2){return true;}
    if(a%2==0){return false;}
    for(int i=3; i<Math.ceil(Math.pow(a,.5)); i+=2){
      if(a%i==0){return false;}}
    return true;}
  public static int maxpower(int a, int b){
    int count=0;
    while(a%b==0){a=a/b;
      count++;}
  return count;}
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int a=scan.nextInt();
    int b=scan.nextInt();
    int count=0;
    int countfail=0;
    if(a>5 && isPrime(a) && b%a!=0){countfail++;}
    if(b>5 && isPrime(b) && a%b!=0){countfail++;}
    for(int i=7; i<Math.max(a,b); i+=2){
      if(isPrime(i) && maxpower(a,i)!=maxpower(b,i)){countfail++;}}
    count+=Math.abs(maxpower(a,2)-maxpower(b,2));
    count+=Math.abs(maxpower(a,3)-maxpower(b,3));
    count+=Math.abs(maxpower(a,5)-maxpower(b,5));
    if(countfail>0){
      System.out.println(-1);}
    else{
      System.out.println(count);}}
}

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by Timur on 13.12.2016.
 */
public class _371B {
    static ArrayList<Integer> list = new ArrayList<>();

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a = in.nextInt();
        int b = in.nextInt();
        int gcd = gcd(a, b);

        dfs(gcd, 0, a);
        dfs(gcd, 0, b);

        out.print(list.size() == 2 ? list.get(0) + list.get(1) : -1);
        out.close();
    }

    public static void dfs(int gcd, int steps, int number){
        if(gcd == number)
            list.add(steps);
        if(gcd * 2 <= number) dfs(gcd * 2, steps + 1, number);
        if(gcd * 3 <= number) dfs(gcd * 3, steps + 1, number);
        if(gcd * 5 <= number) dfs(gcd * 5, steps + 1, number);
    }

    public static int gcd(int a, int b){
        if(b == 0) return a;
        return gcd(b, a % b);
    }
}

import java.util.Scanner;

/**
 * Created by Michael on 9/10/14.
 */
public class B_218 {
    public static void main(String...bob) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int gcd = gcd(a, b);
        a /= gcd;
        b /= gcd;
        if(a == b){
            System.out.println(0);
        }
        else {
            int[] divide = {2, 3, 5};
            for (int i = 0; i < 3; i++) {
                if (a % divide[i] != 0 || b % divide[i] != 0) {
                    System.out.println(-1);
                    return;
                }
            }
            int count = 0;
            for (int i = 2; i >= 0; i--) {
                while (a % divide[i] == 0) {
                    count++;
                    a /= divide[i];
                }
                while (b % divide[i] == 0) {
                    count++;
                    b /= divide[i];
                }
            }
            System.out.println(count);
        }
    }
    public static int gcd(int a, int b){
        if(a == 0)
            return b;
        return gcd(b % a, a);
    }
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class T371B {

	int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public void solve(int a, int b) {
		int c = gcd(a, b);
		int ans = 0;

		int[] x = {2, 3, 5};
		int[] y = {a / c, b / c};

		for (int i = 0; i < 2; i ++) {
			if (y[i] > 1) {
				for (int j = 0; j < 3; j ++)
					if (y[i] % x[j] == 0) {
						int z = y[i] / x[j];
						ans += z;
						y[i] /= (z * x[j]);
					}

				if (y[i] > 1) {
					System.out.println(-1);
					return;
				}
			}
		}
		System.out.println(ans);

	}
	public static void main(String[] args) {
		FastScanner in = new FastScanner();

		new T371B().solve(in.nextInt(), in.nextInt());

	}
	static class FastScanner {

		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

	}
}

import java.util.*;
import java.io.*;
public class Main {
    static BufferedReader reader
		= new BufferedReader(new InputStreamReader(System.in));
    static StringBuilder out = new StringBuilder();

    public static void main(String[] args){
        int a, b;
        int[] inp = nextIntArray();
        a = inp[0];
        b = inp[1];
        int cnt = 0;
        int divA = 2;
        int divB = 2;
        while (a != b && divA <= a && divB <= b){
            if (a < b){
                while (b % divB != 0){
                    divB ++;
                }
                b /= divB;
            } else {
                while (a % divA != 0){
                    divA ++;
                }
                a /= divA;
            }
            cnt ++;
        }
        if (a == b){
            out.append(cnt);
        } else {
            out.append(-1);
        }

        System.out.println(out);
    }

    // the followings are methods to take care of inputs.
    static int nextInt(){
        return Integer.parseInt(nextLine());
    }
    static int nextLong(){
        return Integer.parseInt(nextLine());
    }
    static int[] nextIntArray(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){
            ary[i] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static int[] nextIntArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArray(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length];
        for (int i = 0; i < inp.length; i++){
            ary[i] = Long.parseLong(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Long.parseLong(inp[i]);
        }
        return ary;
    }
	static String nextLine(){
		try {
			return reader.readLine().trim();
		} catch (Exception e){}
		return null;
	}
}

import java.util.*;
public class twenty{
	public static void main(String[] args) {
		Scanner scn =new Scanner(System.in);
		int a= scn.nextInt();
		int b= scn.nextInt();
		// System.out.println("a="+a+"b="+b);
		int count=0;
		boolean modified=true;
		// System.out.println("check point 1");

		while(a!=b &&modified)
		{

			// System.out.println("a="+a+"b="+b);
			count++;
			modified=false;
			if(a%2==0)
			{
				a=a/2;
				modified=true;
			}
			else if(a%3==0)
			{
				a=a/3;
				modified=true;
			}
			else if(a%5==0)
			{
				a=a/5;
				modified=true;
			}
			if(b%2==0)
			{
				b=b/2;
				modified=true;
			}
			else if(b%3==0)
			{
				b=b/3;
				modified=true;
			}
			else if(b%5==0)
			{
				b=b/5;
				modified=true;
			}
			// count++;
		}
		// System.out.println("after while loop");
		if(a==b)
		{
			System.out.println(count);
		}
		else
		{
			System.out.println(-1);
		}

	}
}

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.TreeSet;

public class FoxDividingCheese  {
	public static class t  implements Comparable<t>{
		int val;
		int l;

		public t(int val, int l) {
			super();
			this.val = val;
			this.l = l;
		}

		@Override
		public int compareTo(t o) {
			// TODO Auto-generated method stub
			return val-o.val;
		}

	}

	public static void main(String[] args) throws IOException {
		int val[] = new int[2];
		Reader r = new Reader();
		int a = r.nextInt();
		int b = r.nextInt();
		if (a == b) {
			System.out.println(0);
			return;
		}
		PriorityQueue<t> q = new PriorityQueue<t>(new Comparator<t>() {
			  public int compare(t node1, t node2)
		        {
				  return node1.val-node2.val;
		        }
		});
		TreeSet<t> s = new TreeSet<t>(Collections.reverseOrder());
		TreeSet<t> f = new TreeSet<t>(Collections.reverseOrder());

		q.add(new t(a, 0));
		s = list(s, q);
		q.add(new t(b, 0));
		f = list(f, q);
		/*
		 * for (t d : s) { System.out.print(" s--> " + d.val + " " + d.l); }
		 * System.out.println();
		 *
		 * for (t d : f) { System.out.print(" l--> " + d.val + " " + d.l); }
		 * System.out.println();
		 */
		int l = 0, h = 0;
		System.out.println("size"+f.size()+" "+s.size());
		while (l < f.size() && h < s.size()) {
			if (s.first().val == f.first().val) {
				System.out.println(s.first().l+f.first().l);
				return;
			} else if (s.first().val > f.first().val) {
				s.pollFirst();
			} else {
				f.pollFirst();
			}
	//		System.out.print("-->"+l+" "+h);
		}
		System.out.println(-1);

	}

	private static TreeSet<t> list(TreeSet<t> s, PriorityQueue<t> q) {
		// TODO Auto-generated method stub
		while (!q.isEmpty()) {
			t b = q.poll();
				int j=b.val;
			if (j % 2 == 0 && !q.contains(j / 2)) {
				q.add(new t(j / 2, b.l + 1));
			}
			if (j% 3 == 0 && !q.contains(j / 3))
				q.add(new t(j / 3, b.l + 1));
			if (j % 5 == 0 && !q.contains(j / 5))
			{//System.out.println(j+" "+b.l);
			t a=new t(j / 5, b.l + 1);
			q.add(a);
			}
			s.add(b);
		}
		return s;
	}

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

}

import java.io.*;
import java.util.*;
public class Main{
    private static void solver(InputReader sc, PrintWriter out) throws Exception {
        int x = sc.nextInt();
        int y = sc.nextInt();
        int count=0;
        if(x==y) {
            out.println(0);
            return;
        }
        while(true){

            if(x > y){
                if(x%2==0)
                    x /=2;
                else if(x%3==0){
                    x = x/3;
                }
                else if(x%5==0){
                    x /=5;
                }
                else
                    break;
                count++;
            }
            else if(x < y){
                if(y%2==0)
                    y /=2;
                else if(y%3==0){
                    y = y/3;
                }
                else if(y%5==0){
                    y /=5;
                }
                else
                    break;
                count++;
            }
            else
                break;
        }
        if(x==y)
            out.println(count);
        else
            out.println(-1);
    }
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int[] readIntArray(int n){
            int arr[] = new int[n];
            for(int i=0;i<n;i++) arr[i] = nextInt();
            return arr;
        }
    }
}
class Pair  {
    int x;
    int y;

    Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pair pair = (Pair) o;
        return x == pair.x &&
                y == pair.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }
}

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        tk = new StringTokenizer(in.readLine());
        int a = parseInt(tk.nextToken()),b = parseInt(tk.nextToken());

        List<Integer> A = new ArrayList<>();
        for(int i=2; i*i<=a; i++) {
            while(a%i==0) {
                A.add(i);
                a /= i;
                if(i!=2 && i!=3 && i!=5) {
                    System.out.println("-1");
                    return;
                }
            }
        }
        if(a>1) {
            if(a!=2 && a!=3 && a!=5) {
                System.out.println("-1");
                return;
            }
            A.add(a);
        }

        List<Integer> B = new ArrayList<>();
        for(int i=2; i*i<=b; i++) {
            while(b%i==0) {
                B.add(i);
                b /= i;
                if(i!=2 && i!=3 && i!=5) {
                    System.out.println("-1");
                    return;
                }
            }
        }
        if(b>1) {
            if(b!=2 && b!=3 && b!=5) {
                System.out.println("-1");
                return;
            }
            B.add(b);
        }
        int [] f1 = new int[6];
        int [] f2 = new int[6];
        for(int x : A)
            f1[x]++;
        for(int x : B)
            f2[x]++;

        System.out.println(abs(f1[2]-f2[2])+abs(f1[3]-f2[3])+abs(f1[5]-f2[5]));
    }

}

import java.util.*;
import java.awt.*;

public class FoxDividingCheese {
	Scanner in = new Scanner(System.in);

	public static void main(String args[]) {

		new FoxDividingCheese().go();
	}

	public void go() {
		int a = in.nextInt();
		int b = in.nextInt();
		boolean done=false;
		LinkedList<Point> q= new LinkedList<Point>();
		LinkedList<Integer> moves= new LinkedList<Integer>();
		q.add(new Point(a,b));
		moves.add(0);
		while(!q.isEmpty()){
			Point  p= q.poll();
			int m = moves.poll();
			if(p.x==p.y){
				System.out.println(m);
				done =true;
				break;
			}
			if(p.x>p.y){
				if(p.x%2==0){
					if(p.x/2==p.y){
						System.out.println(m);
						done =true;
						break;
					}
					q.add(new Point(p.x/2, p.y));
					moves.add(m+1);
				}
				if(p.x%3==0){
					if(p.x/3==p.y){
						System.out.println(m);
						done =true;
						break;
					}
					q.add(new Point(p.x/3, p.y));
					moves.add(m+1);
				}
				if(p.x%5==0){
					if(p.x/5==p.y){
						System.out.println(m);
						done =true;
						break;
					}
					q.add(new Point(p.x/5, p.y));
					moves.add(m+1);
				}
			}else{
				if(p.y%2==0){
					if(p.x==p.y/2){
						System.out.println(m);
						done =true;
						break;
					}
					q.add(new Point(p.x, p.y/2));
					moves.add(m+1);
				}
				if(p.y%3==0){
					if(p.x==p.y/3){
						System.out.println(m);
						done =true;
						break;
					}
					q.add(new Point(p.x, p.y/3));
					moves.add(m+1);
				}
				if(p.y%5==0){
					if(p.x==p.y/5){
						System.out.println(m);
						done =true;
						break;
					}
					q.add(new Point(p.x, p.y/5));
					moves.add(m+1);
				}
			}
		}
		if(!done)
			System.out.println(-1);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author el-Bishoy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Div2B_371_FoxDividingCheeze solver = new Div2B_371_FoxDividingCheeze();
        solver.solve(1, in, out);
        out.close();
    }

    static class Div2B_371_FoxDividingCheeze {
        private boolean found = false;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int a = in.nextInt(), b = in.nextInt();

            if (a == b) {
                out.println(0);
                return;
            }

            boolean possible = true;
            int cnt = 0;
            while (a != b && possible && !found) {

                possible = false;
                int max = Math.max(a, b);
                int min = Math.min(a, b);

                if (max % 2 == 0) {
                    int fox = max / 2;
                    max = max - fox;
                    cnt++;
                    possible = true;

                    if (max == min || max == (double) (1 / 2) * min || max == (double) (1 / 3) * min || max == (double) (1 / 5) * min) {
                        found = true;
                        break;

                    }
                } else if (max % 3 == 0) {
                    int fox = (2 * max) / 3;
                    max = max - fox;
                    cnt++;
                    possible = true;
                    if (max == min || max == (double) (1 / 2) * min || max == (double) (1 / 3) * min || max == (double) (1 / 5) * min) {
                        found = true;
                        break;

                    }

                } else if ((max % 5 == 0)) {
                    int fox = (4 * max) / 5;
                    max = max - fox;
                    cnt++;
                    possible = true;
                    if (max == min || max == (double) (1 / 2) * min || max == (double) (1 / 3) * min || max == (double) (1 / 5) * min) {
                        found = true;
                        break;

                    }

                }

                a = max;
                b = min;
            }

            if (possible)
                out.println(cnt);
            else
                out.println(-1);

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}

import java.io.*;
import java.util.StringTokenizer;

public class A {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int a = sc.nextInt(), b = sc.nextInt(), ans = 0;
        while (a != b && a > 0 && b > 0) {
            if (a > b) a = eat(a);
            else b = eat(b);
            ans++;
        }
        out.println(a > 0 && b > 0? ans : -1);
        out.flush();
        out.close();
    }

    static int eat(int x) {
        for (int i = 2; i * i < x; i++) {
            if(x % i == 0)
                return x / i;
        }
        return -1;
    }

    static class Scanner
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));}
        public Scanner(String file) throws Exception {br = new BufferedReader(new FileReader(file));}
        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
        public String nextLine()throws IOException{return br.readLine();}
        public int nextInt() throws IOException {return Integer.parseInt(next());}
        public double nextDouble() throws IOException {return Double.parseDouble(next());}
        public char nextChar()throws IOException{return next().charAt(0);}
        public Long nextLong()throws IOException{return Long.parseLong(next());}
        public boolean ready() throws IOException{return br.ready();}
        public void waitForInput() throws InterruptedException {Thread.sleep(4000);}
    }
}

import java.text.ParseException;
import java.util.*;
import java.io.*;
import java.math.BigInteger;

import static java.lang.Math.*;

    public class solver {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;

    BufferedReader in;
    static PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
             in = new BufferedReader(new InputStreamReader(System.in));
             out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch (Exception e){
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException{
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException{
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException{
        return Double.parseDouble(readString());
    }

    public static void main(String[] args) throws IOException, ParseException{
        new solver().run();
    }

    long timeBegin, timeEnd;

    void time(){
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }
    int[] iMas(int n) throws IOException{
        int[] a=new int[n];
        for (int i=0;i<n;i++){
            a[i]=readInt();
        }
        return a;
    }
    void oMas(int[] a){
        for (int i=0;i<a.length;i++){
            out.println(a[i]);
        }
    }

    int gcd(int a,int b){
        if (b==0) return a;
        return gcd(b, a%b);
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a,int b){
            this.a=a;
            this.b=b;
        }

        public int compareTo(Pair arg0) {
            if (a>arg0.a) return 1;
            if (a<arg0.a) return -1;
            return b-arg0.b;
        }
    }

    void dfs1(int a,int kol){
        if (a%2==0) {
            list1.add(new Pair(a/2,kol+1));
            dfs1(a/2,kol+1);
        }
        if (a%3==0){
            list1.add(new Pair(a/3,kol+1));
            dfs1(a/3,kol+1);
        }
        if (a%5==0){
            list1.add(new Pair(a/5,kol+1));
            dfs1(a/5,kol+1);
        }
    }

    void dfs2(int a,int kol){
        if (a%2==0) {
            list2.add(new Pair(a/2,kol+1));
            dfs2(a/2,kol+1);
        }
        if (a%3==0){
            list2.add(new Pair(a/3,kol+1));
            dfs2(a/3,kol+1);
        }
        if (a%5==0){
            list2.add(new Pair(a/5,kol+1));
            dfs2(a/5,kol+1);
        }
    }

    ArrayList<Pair> list1;
    ArrayList<Pair> list2;
    void solve() throws IOException{
        int a=readInt();
        int b=readInt();

        list1=new ArrayList<Pair>();
        list2=new ArrayList<Pair>();

        if (a==b){
            out.println(0);
            return;
        }
        dfs1(a,0);
        dfs2(b,0);

        Collections.sort(list1);
        Collections.sort(list2);
        int right=0;
        int answer=Integer.MAX_VALUE;
        for (int i=0;i<list1.size();i++){
            while (right<list2.size() && list2.get(right).compareTo(list1.get(i))==-1) right++;
            if (right==list2.size() || list1.get(i).a!=list2.get(right).a) continue;
            answer=Math.min(answer,list1.get(i).b+list2.get(right).b);
        }
        if (answer==Integer.MAX_VALUE){
            out.println(-1);
            return;
        }
        out.println(answer);

    }

    public void run() throws IOException, ParseException{

        init();
        long h=System.currentTimeMillis();
        solve();
        System.err.println(System.currentTimeMillis()-h);
        out.close();
    }

}

import java.util.*;
import java.io.*;
import java.lang.*;

public class Code90
{

	private static long mod = 1000000007;
	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}
	}

	static class SegmentTree
	{
		int st[];

		SegmentTree(int[] a,int n)
		{
			int x = (int)Math.ceil(Math.log(n)/Math.log(2));

			int Max_Size = 2*(int)(Math.pow(2, x))-1;

			st = new int[Max_Size];

			constructSegTreeUtil(a,0,n-1,0);
		}

		int getMid(int start,int end)
		{
			return (start+end)/2;
		}

		int constructSegTreeUtil(int[] a,int ss,int se,int si)
		{
			if(ss==se)
			{
				st[si] = a[ss];
				return a[ss];
			}

			int mid = getMid(ss, se);
			st[si] = constructSegTreeUtil(a, ss, mid, 2*si+1)+
						constructSegTreeUtil(a, mid+1, se, 2*si+2);

			return st[si];
		}

		int getSum(int n, int qs, int qe)
		{
			if(qs<0 || qe>n-1 || qs>qe)
				return -1;

			return getSumUtil(0,n-1,qs,qe,0);
		}

		int getSumUtil(int ss, int se,int qs, int qe, int si)
		{
			if(qs<=ss && qe>=se)
				return st[si];

			if(qs>se || qe<ss)
				return 0;

			int mid = getMid(ss, se);

			return getSumUtil(ss, mid, qs, qe, 2*si+1)+
					getSumUtil(mid+1, se, qs, qe, 2*si+2);
		}

		void updateValue(int[] a, int n, int i, int new_value)
		{
			if(i<0 || i>n-1)
				return;

			int diff = new_value - a[i];

			a[i] = new_value;

			updateValueUtil(0,n-1,i,diff,0);
		}

		void updateValueUtil(int ss, int se, int i, int diff, int si)
		{
			if(i<ss || i>se)
				return;

			st[si]+=diff;
			if(ss!=se)
			{
				int mid = getMid(ss, se);
				updateValueUtil(ss, mid+1, i, diff, 2*si+1);
				updateValueUtil(mid+1, se, i, diff, 2*si+2);
			}
		}
	}

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static ArrayList<Integer> primeFactorization(int n)
	{
		ArrayList<Integer> a =new ArrayList<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(i*i);j<n;j++)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long GCD(long a,long b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static ArrayList<Integer> getPrime(int n)
	{
		ArrayList<Integer> primes = new ArrayList<>();
		int count = 0;
		while(n%2==0)
		{
			count++;
			n/=2;
		}
		primes.add(count);

		count = 0;
		while(n%3==0)
		{
			count++;
			n/=3;
		}
		primes.add(count);

		count = 0;
		while(n%5==0)
		{
			count++;
			n/=5;
		}
		primes.add(count);

		primes.add(n);

		return primes;
	}
	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int a = in.nextInt();
		int b = in.nextInt();

		ArrayList<Integer> A = new ArrayList<>();
		ArrayList<Integer> B = new ArrayList<>();

		A = getPrime(a);
		B = getPrime(b);

		int ans = 0;
		for(int i=0;i<3;i++)
			ans+=(Math.abs(A.get(i)-B.get(i)));

		if(A.get(3)==B.get(3))
			pw.println(ans);
		else
			pw.println("-1");
		pw.flush();
		pw.close();
	}
}

import java.math.BigInteger;
import java.sql.Statement;
import java.util.HashSet;
import java.util.*;

public class Solution{

   public int solve(int a , int b){
       int counter1[] =  new int[3];
       int counter2[] = new int[3];
       while (a%2 == 0) {
           counter1[0]++;
           a/=2;
       }
       while (a%3 == 0) {
           counter1[1]++;
           a/=3;
       }
       while (a%5 == 0) {
           counter1[2]++;
           a/= 5;
       }

       if(a!= 1)
           return -1;

       while (b%2 == 0) {
           counter2[0]++;
           b/=2;
       }
       while (b%3 == 0) {
           counter2[1]++;
           b/=3;
       }
       while (b%5 == 0) {
           counter2[2]++;
           b/=5;
       }

       if(b!= 1)
           return -1;
        int ans = 0;
       for(int i=0 ; i<3 ; i++)
           ans+= Math.abs(counter1[i] - counter2[i]);
   return ans;
   }
    public static void main(String[] args) {
        Solution s = new Solution();
        Scanner input = new Scanner(System.in);
        System.out.println(s.solve(input.nextInt(),input.nextInt()));
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class zizo {
	static ArrayList<Integer> primes;
	static boolean[] isPrime;
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int a = sc.nextInt(), b = sc.nextInt();
		primes = new ArrayList<Integer>();
		seive((int)1e5);
		TreeMap<Integer, Integer> map_a = new TreeMap(), map_b = new TreeMap();
		primeFactors(a, map_a);
		primeFactors(b, map_b);
		int ans = 0;
		ans = ans + Math.abs(map_a.getOrDefault(2, 0) - map_b.getOrDefault(2, 0)) + Math.abs(map_a.getOrDefault(3, 0) - map_b.getOrDefault(3, 0)) + Math.abs(map_a.getOrDefault(5, 0) - map_b.getOrDefault(5, 0));
		map_a.remove(2);map_a.remove(3);map_a.remove(5);map_b.remove(2);map_b.remove(3);map_b.remove(5);
		boolean flag = true;
		while(map_a.size() > 0 && map_b.size() > 0) {
			Map.Entry<Integer, Integer> x = map_a.pollFirstEntry(), y = map_b.pollFirstEntry();
			if(x.getKey() != y.getKey() || x.getValue() != y.getValue()) {
				flag = false;
				break;
			}
		}
		if(!flag || map_a.size() > 0 || map_b.size() > 0)
			out.println(-1);
		else
			out.println(ans);
		out.flush();
		out.close();
	}

	public static void seive(int n) {
		isPrime = new boolean[n + 1];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for(int i = 2; i * i <= n; i++)
			if(isPrime[i])
				for(int j = i; i * j <= n; j++)
					isPrime[i * j] = false;
		for(int i = 0; i <= n; i++)
			if(isPrime[i])
				primes.add(i);
	}

	public static void primeFactors(int x, TreeMap<Integer, Integer> map) {
		int idx = 0;
		while(idx < primes.size() && primes.get(idx) * primes.get(idx) <= x) {
			if(x % primes.get(idx) == 0) {
				map.put(primes.get(idx), map.getOrDefault(primes.get(idx), 0) + 1);
				x/=primes.get(idx);
			}
			else
				idx++;
		}
		if(x > 1)
			map.put(x, 1);
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException{return Double.parseDouble(next());}

		public boolean ready() throws IOException {return br.ready();}

	}
}

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);

		int first = s.nextInt();
		int second = s.nextInt();

//		int sf = first;
//		int ss = second;
//		while (sf != ss) {
//			if (sf > ss) {
//				sf -= ss;
//			} else {
//				ss -= sf;
//			}
//		}
//
//		System.out.println(sf);
//		System.out.println(ss);

		boolean fail = false;

		int count = 0;
		while (first != second) {
			if (first > second) {
				first = cut(first);

				if (first == -1) {
					fail = true;
					break;
				}
			} else {
				second = cut(second);

				if (second == -1) {
					fail = true;
					break;
				}
			}

			count++;
		}

		if (fail) {
			System.out.println("-1");
		} else {
			System.out.println(count);
		}
	}

	public static int cut(int c) {
		if (c % 2 == 0) {
			return c / 2;
		}
		if (c % 3 == 0) {
			return c / 3;
		}
		if (c % 5 == 0) {
			return c / 5;
		}

		return -1;
	}

//	public static void main(String args[]) {
//		Scanner s = new Scanner(System.in);

//		String recipe = s.nextLine();
//
//		int bread = s.nextInt();
//		int col = s.nextInt();
//		int cheese = s.nextInt();
//
//		int pBread = s.nextInt();
//		int pCol = s.nextInt();
//		int pCheese = s.nextInt();
//
//		long r = s.nextLong();
//
//		long count = 0;
//
//		boolean cont = true;
//		while (cont) {
//			for (char c : recipe.toCharArray()) {
//				if (c == 'B') {
//					if (bread > 0) {
//						bread--;
//					} else if (r >= pBread) {
//						r -= pBread;
//					} else {
//						cont = false;
//					}
//				}
//				if (c == 'S' && cont) {
//					if (col > 0) {
//						col--;
//					} else if (r >= pCol) {
//						r -= pCol;
//					} else {
//						cont = false;
//					}
//				}
//				if (c == 'C' && cont) {
//					if (cheese > 0) {
//						cheese--;
//					} else if (r >= pCheese) {
//						r -= pCheese;
//					} else {
//						cont = false;
//					}
//				}
//			}
//
//			if (cont) {
//				count++;
//			}
//
//			if (bread == 0 && col == 0 && cheese == 0) {
//				break;
//			}
//		}
//
//		long price = 0;
//		for (char c : recipe.toCharArray()) {
//			if (c == 'B') price += pBread;
//			if (c == 'S') price += pCol;
//			if (c == 'C') price += pCheese;
//		}
//
//		count += r / price;
//
//		System.out.println(count);
//	}

//	public static void main(String args[]) {
//		Scanner s = new Scanner(System.in);
//
//		int l = s.nextInt();
//		int k = s.nextInt();
//
//		HashMap<Integer, Integer> h = new HashMap<Integer, Integer>();
//		for (int i = 0; i < l; i++) {
//			int el = s.nextInt();
//
//			int key = i % k;
//
//			if (!h.containsKey(key)) {
//				h.put(key, 0);
//			}
//
//			if (el == 1) {
//				h.put(key, h.get(key) + 1);
//			}
//		}
//
//		int count = 0;
//
//		for (int key : h.keySet()) {
//			int val = h.get(key);
//			count += Math.min(val, l / k - val);
//		}
//
//		System.out.println(count);
//	}

}

import java.util.Scanner;

public class main {
    static int max, min;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt(), b = scanner.nextInt();
        scanner.close();
        int counter = 0;
        findMaxAndMin(a, b);
        while (max > 1 && min > 1) {

            if (max == min) {
//                System.out.println("counter = " + counter + " , max = min =" + max);
                System.out.println(counter);
                return;
            }
            counter++;
            if (max % 2 == 0) {
                max -= max / 2;
            } else if (max % 3 == 0) {
                max -= max * 2 / 3;
            } else if (max % 5 == 0) {
                max -= max * 4 / 5;
            } else break;

            findMaxAndMin(max, min);

        }

        System.out.println(-1);

    }

    private static void findMaxAndMin(int a, int b) {

        if (a > b) {
            max = a;
            min = b;
        } else {
            min = a;
            max = b;
        }
    }

}

import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Solution implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");
    static String[] args;

    public static void main(String[] args) {
        Solution.args = args;
        new Thread(null, new Solution(), "", 256 * (1L << 20)).start();
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            if (System.getProperty("ONLINE_JUDGE") != null) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                String file = "input.txt";
                if (args.length > 0) {
                    file = args[0];
                }
                in = new BufferedReader(new FileReader(file));
                out = new PrintWriter("output.txt");
            }
            Locale.setDefault(Locale.US);
            solve();
            in.close();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    // solution
    int[] pieces(int x) {
        int[] result = new int[3];
        if ((x & 1) == 0)
            result[0] = x>>1;
        if (x % 3 == 0)
            result[1] = x/3;
        if (x % 5 == 0)
            result[2] = x/5;
        return result;
    }

    int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a%b);
    }

    void solve() throws IOException {
        int a = readInt(), b = readInt();
        /* if (a == b) { */
        /*     System.out.println(0); */
        /*     return; */
        /* } */
        int g = gcd(a, b);
        int da = a/g;
        int[] dd = new int[3];

        if (da%2 ==0){
            dd[0] = da/2;
            da%=2;
        }
        if (da%3 ==0) {
            dd[1] = da/3;
            da%=3;
        }
        if (da%5 ==0) {
            dd[2] = da/5;
            da%=5;
        }
        if (da != 0 && da != 1) {
            System.out.println("-1");
            return;
        }
        int db = b/g;
        if (db%2 ==0){
            dd[0] += db/2;
            db%=2;
        }
        if (db%3 ==0) {
            dd[1] += db/3;
            db%=3;
        }
        if (db%5 ==0) {
            dd[2] += db/5;
            db%=5;
        }
        if (db != 0 && db != 1) {
            System.out.println("-1");
            return;
        }
        System.out.println(dd[0]+dd[1]+dd[2]);
    }
}

//package CF;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
	public static void main(String[] args) throws Exception {
		Scanner bf = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
		int[] a = { bf.nextInt(), bf.nextInt() };
		int[] b = { 2, 3, 5 };
		int[][] pow = new int[2][3];
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < b.length; j++) {
				while (a[i] % b[j] == 0) {
					pow[i][j]++;
					a[i] /= b[j];
				}
			}
		}
		System.out.println(a[0] +  " " + a[1]);
		if (a[0] != a[1])
			out.println(-1);
		else {
			int ans = 0;
			for (int i = 0; i < pow[0].length; i++)
				ans += Math.abs(pow[0][i] - pow[1][i]);
			out.println(ans);
		}
		out.print(sb);
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

import java.io.*;
import java.util.*;

public class cf371b {
	public static void main(String args[]) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] s = in.readLine().split("\\s+");
		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);

		ArrayList<Integer> afactors = new ArrayList<Integer>();
		ArrayList<Integer> bfactors = new ArrayList<Integer>();

		for(int i = 2; i <= 5; i++) {
			while(a % i == 0) {
				afactors.add(i);
				a /= i;
			}

			while(b % i == 0) {
				bfactors.add(i);
				b /= i;
			}
		}

		ArrayList<Integer> sharedfactors = new ArrayList<Integer>();

		for(int i = 0; i < afactors.size(); i++) {
			if(bfactors.contains(afactors.get(i))) {
				sharedfactors.add(afactors.get(i));
				bfactors.remove((Integer) afactors.remove(i));
				i--;
			}
		}

		if(a > 1 || b > 1) { System.out.println(-1); return; }

		System.out.println(afactors.size() + bfactors.size());
	}
}

import java.util.Scanner;

/**
 * Created by Michael on 9/10/14.
 */
public class B_218 {
    public static void main(String...bob) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int gcd = gcd(a, b);
        if(a == b){
            System.out.println(0);
        }
        else {
            int[] divide = {2, 3, 5};
            a /= gcd;
            b /= gcd;
            boolean aGood = false, bGood = false;
            for (int i = 0; i < 3; i++) {
                if(a % divide[i] == 0)
                    aGood = true;
                if(b % divide[i] == 0)
                    bGood = true;
            }
            if(!aGood || !bGood)
                System.out.println(-1);
            else {

                int count = 0;
                for (int i = 2; i >= 0; i--) {
                    while (a % divide[i] == 0) {
                        count++;
                        a /= divide[i];
                    }
                    while (b % divide[i] == 0) {
                        count++;
                        b /= divide[i];
                    }
                }
                System.out.println(count);
            }
        }
    }
    public static int gcd(int a, int b){
        if(a == 0)
            return b;
        return gcd(b % a, a);
    }
}

import java.math.BigInteger;
import java.util.Scanner;

public class B371 {
	private static int count = 0;

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int gcdVal = gcd(a, b);

		if(a==b)
		{
			System.out.println(count);
			System.exit(0);
		}

		if(divide(a, gcdVal) && divide(b, gcdVal))
			System.out.println(count);
		else
			System.out.println("-1");

		in.close();
	}

	public static int gcd(int a, int b) {
	    BigInteger b1 = BigInteger.valueOf(a);
	    BigInteger b2 = BigInteger.valueOf(b);
	    BigInteger gcd = b1.gcd(b2);
	    return gcd.intValue();
	}

	public static boolean divide(int a, int gcd)
	{
		if(a%2 == 0)
		{
			count ++;
			if(a/2 == gcd)
				return true;
			else
				return divide(a/2, gcd);
		}
		else if(a%3 == 0)
		{
			count++;
			if(a/3 == gcd)
				return true;
			else
				return divide(a/3, gcd);
		}
		else if(a%5 == 0)
		{
			count++;
			if(a/5 == gcd)
				return true;
			else
				return divide(a/5, gcd);
		}
		return false;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class FoxDividingCheese {

  static BufferedReader in;
  static PrintWriter out;
  static StringTokenizer tok;

  static void solve() throws Exception {
    long a = nextLong(), b = nextLong();
    List<Long> la = gen(a);
    List<Long> lb = gen(b);
    int i = la.size() - 1, j = lb.size() - 1;
    while (i >= 0 && j >= 0)
      if (la.get(i) == lb.get(j))
        break;
      else if (la.get(i) > lb.get(j))
        i--;
      else
        j--;
    long x = la.get(i);
    int xa = count(a, x);
    int xb = count(b, x);
    out.println((xa == -1 || xb == -1) ? -1 : xa + xb);
  }

  static List<Long> gen(long a) {
    List<Long> list = new ArrayList<>();
    for (long i = 1; i * i <= a; i++)
      if (a % i == 0) {
        list.add(i);
        if (a / i != i)
          list.add(a / i);
      }
    Collections.sort(list);
    return list;
  }

  static int count(long a, long b) {
    if (a == b)
      return 0;
    long c = a / b;
    int count = 0;
    while (c != 1)
      if (c % 2 == 0) {
        c /= 2;
        count++;
      } else if (c % 3 == 0) {
        c /= 3;
        count++;
      } else if (c % 5 == 0) {
        c /= 5;
        count++;
      } else {
        return -1;
      }
    return count;
  }

  public static void main(String args[]) {
    try {
      in = new BufferedReader(new InputStreamReader(System.in));
      out = new PrintWriter(new OutputStreamWriter(System.out));
      solve();
      in.close();
      out.close();
    } catch (Throwable e) {
      e.printStackTrace();
      System.exit(1);
    }
  }

  static int nextInt() throws IOException {
    return Integer.parseInt(next());
  }

  static int[] nextIntArray(int len, int start) throws IOException {
    int[] a = new int[len];
    for (int i = start; i < len; i++)
      a[i] = nextInt();
    return a;
  }

  static long nextLong() throws IOException {
    return Long.parseLong(next());
  }

  static long[] nextLongArray(int len, int start) throws IOException {
    long[] a = new long[len];
    for (int i = start; i < len; i++)
      a[i] = nextLong();
    return a;
  }

  static String next() throws IOException {
    while (tok == null || !tok.hasMoreTokens()) {
      tok = new StringTokenizer(in.readLine());
    }
    return tok.nextToken();
  }

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package codeforces;

/**
 *
 * @author aidos
 */
import java.util.*;
public class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k=sc.nextInt();
    if(n==k) System.out.println(0);
    else if(n==1 || k==1){
        System.out.println(Operations(n,k,0));
    }
    else{
     Map <Integer,Integer> hm=factorize(n);
     Map <Integer,Integer> hm1 = factorize(k);
    int ret=0;
    int sum=Integer.MAX_VALUE;
     for(int i:hm1.keySet()){
            ret= 0;
            if(hm.containsKey(i)) {
              ret = Operations(hm.get(i),hm1.get(i),i);
              if(ret==-1) continue;
              else sum=Math.min(ret,sum);
            }

        }
     if(sum==Integer.MAX_VALUE) System.out.print(-1);
     else System.out.print(sum);
    }
    }

    public static int Operations(int n,int m,int v){
        int ret=0;
        int sum=0;
        int sum1=0;
        while(n!=1 && sum!=-1){
            if(n%5==0) {n =n/5;sum++;}
            else if(n%3==0) {n=n/3;sum++;}
            else if(n%2==0) {n=n/2;sum++;}
            else sum=-1;
        }
         while(m!=1 && sum1!=-1){
            if(m%5==0) {m=m/5;sum1++;}
            else if(m%3==0) {m=m/3;sum1++;}
            else if(m%2==0) {m=m/2; sum1++;}

            else sum1=-1;

        }
         if(sum1==-1 || sum==-1) return -1;

        return sum1+sum;
    }

     public static Map<Integer, Integer> factorize(int a){

        Map<Integer,Integer> m = new HashMap<Integer,Integer>();
        for(int i=2;i<=a/2;i++){
            if(a%i==0) m.put(i, a/i);
        }
        m.put(a, 1);
        return m;
    }
    }

import java.util.*;
import java.io.*;
import java.lang.*;

public class Code90
{

	private static long mod = 1000000007;
	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}
	}

	static class SegmentTree
	{
		int st[];

		SegmentTree(int[] a,int n)
		{
			int x = (int)Math.ceil(Math.log(n)/Math.log(2));

			int Max_Size = 2*(int)(Math.pow(2, x))-1;

			st = new int[Max_Size];

			constructSegTreeUtil(a,0,n-1,0);
		}

		int getMid(int start,int end)
		{
			return (start+end)/2;
		}

		int constructSegTreeUtil(int[] a,int ss,int se,int si)
		{
			if(ss==se)
			{
				st[si] = a[ss];
				return a[ss];
			}

			int mid = getMid(ss, se);
			st[si] = constructSegTreeUtil(a, ss, mid, 2*si+1)+
						constructSegTreeUtil(a, mid+1, se, 2*si+2);

			return st[si];
		}

		int getSum(int n, int qs, int qe)
		{
			if(qs<0 || qe>n-1 || qs>qe)
				return -1;

			return getSumUtil(0,n-1,qs,qe,0);
		}

		int getSumUtil(int ss, int se,int qs, int qe, int si)
		{
			if(qs<=ss && qe>=se)
				return st[si];

			if(qs>se || qe<ss)
				return 0;

			int mid = getMid(ss, se);

			return getSumUtil(ss, mid, qs, qe, 2*si+1)+
					getSumUtil(mid+1, se, qs, qe, 2*si+2);
		}

		void updateValue(int[] a, int n, int i, int new_value)
		{
			if(i<0 || i>n-1)
				return;

			int diff = new_value - a[i];

			a[i] = new_value;

			updateValueUtil(0,n-1,i,diff,0);
		}

		void updateValueUtil(int ss, int se, int i, int diff, int si)
		{
			if(i<ss || i>se)
				return;

			st[si]+=diff;
			if(ss!=se)
			{
				int mid = getMid(ss, se);
				updateValueUtil(ss, mid+1, i, diff, 2*si+1);
				updateValueUtil(mid+1, se, i, diff, 2*si+2);
			}
		}
	}

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static ArrayList<Integer> primeFactorization(int n)
	{
		ArrayList<Integer> a =new ArrayList<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(i*i);j<n;j++)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long GCD(long a,long b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int a = in.nextInt();
		int b = in.nextInt();

		ArrayList<Integer> A = new ArrayList<>();
		ArrayList<Integer> B = new ArrayList<>();

		A = primeFactorization(a);
		B = primeFactorization(b);

		int count = 0;
		if(a==b)
			pw.print(count);
		else{
		while(true)
		{
			int gcd = GCD(a, b);
			if(gcd==1)
			{
				pw.println("-1");
				break;
			}

			if(a==b)
			{
				pw.println(count);
				break;
			}

			if(a>=b)
			{
				a -= (a*(A.get(0)-1))/A.get(0);
				A.remove(0);
			}
			else
			{
				b -= (b*(B.get(0)-1))/B.get(0);
				B.remove(0);
			}
			count++;
		}

		}
		pw.flush();
		pw.close();
	}
}

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if (a==b){
            System.out.println(0);
            return;
        }
        else{
            int ans=0;
            int ca5=0,cb5=0;
            while (a%5==0){
                a/=5;
                ca5++;
            }
            while (b%5==0){
                b/=5;
                cb5++;
            }
            int ca3=0,cb3=0;
            while (a%3==0){
                a/=3;
                ca3++;
            }
            while (b%3==0){
                b/=3;
                cb3++;
            }
            int ca2=0,cb2=0;
            while (a%2==0){
                a/=2;
                ca2++;
            }
            while (b%2==0){
                b/=2;
                cb2++;
            }
            ans+=Math.abs(ca5-cb5);
            ans+=Math.abs(ca3-cb3);
            ans+=Math.abs(ca2-cb2);
            if (a==b){
                System.out.println(ans);
            }
            else{
                System.out.println(0);
            }

        }

    }
}

import java.util.Scanner;

public class FoxDividingCheese {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		long a=scn.nextLong();
		long b=scn.nextLong();
		int op=0;

		if(a==b)
			System.out.println(0);

		long c=a;
		long d=b;
		int countc=0;
		int countd=0;

		//5555555555555555555555555555555

		while(true){
			if(c%5==0){
				c=c/5;
				countc++;
			}
			else
				break;
		}

		while(true){
			if(d%5==0){
				d=d/5;
				countd++;
			}
			else
				break;
		}

		if(countc>countd){
			for(int i=0;i<countc-countd;i++){
				op++;
			}
		}else if(countc<countd){
			for(int i=0;i<countd-countc;i++){
				op++;
			}
		}

		//33333333333333333333333333333333333

		countc=0;
		countd=0;

		while(true){
			if(c%3==0){
				c=c/3;
				countc++;
			}
			else
				break;
		}

		while(true){
			if(d%3==0){
				d=d/3;
				countd++;
			}
			else
				break;
		}

		if(countc>countd){
			for(int i=0;i<countc-countd;i++){
				op++;
			}
		}else if(countc<countd){
			for(int i=0;i<countd-countc;i++){
				op++;
			}
		}

		//22222222222222222222222222222222222
		countc=0;
		countd=0;

		while(true){
			if(c%2==0){
				c=c/2;
				countc++;
			}
			else
				break;
		}

		while(true){
			if(d%2==0){
				d=d/2;
				countd++;
			}
			else
				break;
		}

		if(countc>countd){
			for(int i=0;i<countc-countd;i++){
				op++;
			}
		}else if(countc<countd){
			for(int i=0;i<countd-countc;i++){
				op++;
			}
		}

		System.out.println(op);

		return;
	}

}

import java.util.*;
import java.io.*;
import java.math.*;
import java.util.HashMap;

public class main
{
    static class Reader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public static void main(String args[])
    {
        Reader sc=new Reader();
        PrintWriter out=new PrintWriter(System.out);
        int a=sc.i();
        int b=sc.i();
        long counter=0;
        while(true)
        {
            if(a==b)
            {
                System.out.println(counter);
                System.exit(0);
            }
            else if(a>b)
            {
                int val=-1;
                for(int i=2;i<=Math.sqrt(a);i++)
                {
                    if(a%i==0)
                    {
                        val=i;
                        break;
                    }
                }
                if(val==-1)
                {
                    System.out.println("-1");
                    System.exit(0);
                }
                a/=val;
            }
            else
            {
                int val=-1;
                for(int i=2;i<=Math.sqrt(b);i++)
                {
                    if(b%i==0)
                    {
                        val=i;
                        break;
                    }
                }
                if(val==-1)
                {
                    System.out.println("-1");
                    System.exit(0);
                }
                b/=val;
            }
            counter++;
        }
    }
}

import java.io.*;
import java.util.*;

public class Tasker4 {

	PrintWriter out;
	BufferedReader input;

	Tasker4() {
		try {
			input = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new FileWriter("output.txt"), true);
			solver();
		} catch (IOException ex) {
			ex.printStackTrace();
			input = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out,true);
			try {
				solver();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} finally {
			try {
				input.close();
			} catch (IOException e) {

			}
			out.close();
		}
	}

	StringTokenizer st = new StringTokenizer("");

	private String nextToken() throws IOException {
		while (!st.hasMoreElements()) {
			st = new StringTokenizer(input.readLine());
		}
		return st.nextToken();
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private Long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private Double nextDouble() throws IOException {
		return Double.valueOf(nextToken());
	}

	public void solver() throws IOException {
		int a = nextInt();
		int b = nextInt();
		int ta = a;
		int tb = b;
		if (a == b) {
			out.print(0);
		} else {
			boolean ok = false;
			long res = 0;
			while (a != b && !ok) {
				boolean oneStep = false;
				boolean twoStep = false;
				if (a > b) {
					if (a % 2 == 0) {
						a/=2;
						res++;
						oneStep = true;
					} else if (a % 3 == 0) {
						a/=3;
						res++;
						oneStep = true;
					} else if (a % 5 == 0) {
						a/=5;
						res++;
						oneStep = true;
					}
				} else {
					if (b % 2 == 0) {
						b/=2;
						res++;
						twoStep = true;
					} else if (b % 3 == 0) {
						b/=3;
						res++;
						twoStep = true;
					} else if (b % 5 == 0) {
						b/=5;
						res++;
						twoStep = true;
					}
				}
				if (!oneStep && !twoStep && a!=b) {
					ok = true;
				}
			}
			int tRes = 0;
			if (ta % tb == 0) {
				int k = ta/tb;
				if (k%2 == 0) {
					tRes += k/2;
				} else if (k % 3 == 0) {
					tRes += k/3;
				} else if (k % 5 == 0) {
					tRes += k/5;
				}

			} else if (tb % ta == 0) {
				int k = tb/ta;
				if (k%2 == 0) {
					tRes += k/2;
				} else if (k % 3 == 0) {
					tRes += k/3;
				} else if (k % 5 == 0) {
					tRes += k/5;
				}
			}
			if (tRes != 0) {
				res = Math.min(res, tRes);
			}
			if (ok)
				out.print(-1);
			else
				out.print(res);
		}
	}

	public static void main(String[] args) {
		new Tasker4();
	}

}

//package codeforces;

import java.io.*;
import java.util.StringTokenizer;

public class FoxDividingCheese {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(in, out);

        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class TaskA {
        public static void solve(InputReader in, PrintWriter out) {

            int a = in.nextInt();
            int b = in.nextInt();

            int[] arr = new int[]{2, 3, 5};

            long result = 0;
            for(int i=0; i<arr.length; i++) {
                int divisor = arr[i];

                long power1 = 0;
                while(a % divisor == 0) {
                    a/=divisor;
                    power1++;
                }

                long power2 = 0;
                while(b % divisor == 0) {
                    b/=divisor;
                    power2++;
                }
                result += Math.abs(power1 - power2);

            }

            out.println(result);

        }

    }
}

import java.util.*;

import javax.sound.midi.SysexMessage;

public class Main{
    public static void main(String[] args){
        Scanner cin = new Scanner(System.in) ;
        while(cin.hasNext()){
            int a = cin.nextInt() ;
            int b = cin.nextInt() ;
            int ans = 0 ;
            while(a != b){
                int i ;
                if(a > b){
                    for(i = 2 ; i <= 5; i++){
                        if(a % i == 0){
                            a /= i ;
                            break ;
                        }
                    }
                }
                else{
                    for(i = 2 ; i <= 5; i++){
                        if(b % i == 0){
                            b /= i ;
                            break ;
                        }
                    }
                }
                if(i == 6){
                    ans = -1 ;
                    break ;
                }
                ans++ ;
            }
            System.out.printf("%d%n" , ans) ;
        }
    }
}

//package ladderB;

import java.util.HashMap;
import java.util.Scanner;

public class foxDividingCheese {
	static int INF = (int)1e9;
	static HashMap<Integer, Integer> memo;
	static int gcd(int one, int two) {
		if(two==0)return one;
		return gcd(two, one%two);
	}
	static int minWays(int cur) {
		if(cur==1)
		{
			int ans = 0;
			memo.put(cur,ans);
			return ans;
		}
		if(memo.containsKey(cur))
			return memo.get(cur);
		int two = INF;
		int three =INF;
		int four =INF;
		int five = INF;
		if(cur%2==0)
			two = minWays(cur/2)+1;
		if(cur%3==0)
			three = minWays(cur/3)+1;
		if(cur%5==0)
			three = minWays(cur/5)+1;
		int min = Math.min(two, Math.min(three, Math.min(four, five)));
		if(min>=INF)
		{
			memo.put(cur,INF);
			return INF;
		}else {
			memo.put(cur, min);
			return min;
		}
	}
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int one = sc.nextInt();
	int two = sc.nextInt();
	int gcd = gcd(one,two);
	memo = new HashMap<Integer,Integer>();
	one/=gcd;
	two/=gcd;
	if(gcd ==1 &&one!=two)
		System.out.println(-1);
	else if(one ==two)
			System.out.println(0);
	else {
		int firstOne = minWays(one);
		int secondOne = minWays(two);
		//System.out.println(firstOne+" "+secondOne+" "+one+" "+two);
		if(firstOne==INF|| secondOne == INF)
			System.out.println(-1);
		else System.out.println(firstOne+secondOne);
	}
}
}

import java.util.Scanner;

public class EsB {

	/**
	 * @param args
	 */static int ris = Integer.MAX_VALUE;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a,b;
		a = scan.nextInt();
		b = scan.nextInt();
		if(a==b){
			System.out.println(0);
		}else if(a==0||b==0){
			System.out.println(-1);
		}else{
			if(b>a){
				int c = a;
				a=b;
				b=c;
			}

			find(a,b,0);
			if(ris!=Integer.MAX_VALUE){
				System.out.println(ris);
			}else{
				System.out.println(-1);
			}

		}

	}

	private static void find(int a, int b, int step) {
		if(a==b){
			if(step<ris){
				ris=step;
			}

		}

		for(int i=2; i<6; i++){
			if(i!=4){
				if(a%i==0){
					if(a>b){
						find(a/i,b,step+1);
					}else{
						find(b,a/i,step+1);
					}

				}
			}
		}

	}

	private static int mcd(int a, int b) {
		 if (b==0) return a;
		   return mcd(b,a%b);
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.awt.Point;

public class CF_371_B_FOX_DIVIDING_CHESSE {

	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a == b )
		{
			System.out.println(0);
			return;
		}

		ArrayList<Point>cheese1 = new ArrayList<>();
		ArrayList<Point>cheese2 = new ArrayList<>();
		int ele [] = {2,3,5};
		for(int i = 0 ; i < 3 ; i++) {
			if(a % ele[i] == 0)
				cheese1.add(new Point((ele[i]-1)*a/ele[i], ele[i]-1));
			if(b % ele[i] == 0)
				cheese2.add(new Point((ele[i]-1)*b/ele[i], ele[i]-1));
		}

		int ans = -1;
		for(int i = 0 ; i<cheese1.size() ; i++)
			for(int j = 0 ; j < cheese2.size() ; j++)
			{
				if(cheese1.get(i).x == cheese2.get(j).x)
				{

					ans = ans == -1 ? cheese1.get(i).y+cheese2.get(j).y
							: Math.min(ans, cheese1.get(i).y+cheese2.get(j).y);

				}

			}

		System.out.println(ans);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream fileReader) {
			br = new BufferedReader(new InputStreamReader(fileReader));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}

/*
 *
 *   Date: 07 September 2019
 *   Time: 01:03:00
*/
import java.io.*;
import java.util.*;

public class fd
{
  static long min(long a,long b,long c){
         return (long)Math.min(a,(long)Math.min(b,c));
  }
  static int[] maxPow(long a,int pow[]){
       int cnt=0;
       while(a%2==0){
        a=a/2;
        cnt++;
       }
       pow[0]=cnt;
       cnt=0;
       while(a%3==0){
        a=a/3;
        cnt++;
       }
       pow[1]=cnt;
       cnt=0;
       while(a%5==0){
        a=a/5;
        cnt++;
       }
       pow[2]=cnt;
       if(a==1){
        return pow;
       }else{
        return null;
       }

  }
    public static void main(String[] args) throws NumberFormatException, IOException
    {
  Scanner sc = new Scanner(System.in);
   long a=sc.nextLong();
   long b=sc.nextLong();
   int pow1[]=new int[3];
      int pow2[]=new int[3];

int ans1[]=maxPow(a,pow1);
int ans2[]=maxPow(b,pow2);
if(ans1==null || ans2==null){
  System.out.println(-1);
}else{

  long ans=(long)Math.abs(ans1[0]-ans2[0])+(long)Math.abs(ans1[1]-ans2[1])+(long)Math.abs(ans1[2]-ans2[2]);
  System.out.println(ans);
}

    }
}

import java.util.*;
public class Fox
{
	static long hcf(long a,long b)
	{
	if(a==0)
	return 0;
	if(b==0)
	return 0;
	if(a==b)
	return a;
	if(a>b)
	return hcf(a-b,b);
	else
	return hcf(a,b-a);
	}

	public static void main(String[] args)
	 {
	  Scanner s=new Scanner(System.in);
	  long a=s.nextLong();
	  long b=s.nextLong();
	  long k=hcf(a,b);
	  int count=0;
	  long k1=a/k;
	  long k2=b/k;
	  boolean bl=true;
	  while(k1!=1)
	  {
	   if(k1%5==0)
	   {
		k1=k1/5;
		count++;
	    }
	  else if(k1%3==0)
	    {
		k1/=3;
		count++;
	    }
	      else if(k%2==0)
	      {
	       k1/=2;
	       count++;
	      }
	    else
		{bl=false;
		break;}

	  }
	 while(k2!=1)
	  {
	   if(k2%5==0)
	   {
		k2=k2/5;
		count++;
	    }
	  else if(k2%3==0)
	    {
		k2/=3;
		count++;
	    }
	      else if(k2%2==0)
	      {
	       k2/=2;
	       count++;
	      }
	else
	{
	bl=false;
	break;
	}

	  }
	if(bl)
	System.out.println(count);
	else
	System.out.println("-1");
	}
}

import java.util.Scanner;

public class EsB {

	/**
	 * @param args
	 */static long ris = Long.MAX_VALUE;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a,b;
		a = scan.nextLong();
		b = scan.nextLong();
		if(a==b){
			System.out.println(0);
		}else if(a==0||b==0){
			System.out.println(-1);
		}else{
			if(b>a){
				long c = a;
				a=b;
				b=c;
			}

			find(a,b,0);
			if(ris!=Long.MAX_VALUE){
				System.out.println(ris);
			}else{
				System.out.println(-1);
			}

		}

	}

	private static void find(long a, long b, long step) {
		if(a==b){
			if(step<ris){
				ris=step;
			}

		}

		for(int i=2; i<6; i++){

				if(a%i==0){
					if(a>b){
						find(a/i,b,step+1);
					}else{
						find(b,a/i,step+1);
					}

				}

		}

	}

	private static int mcd(int a, int b) {
		 if (b==0) return a;
		   return mcd(b,a%b);
	}

}

import java.util.Scanner;

public class main {
    static int max, min;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt(), b = scanner.nextInt();
        scanner.close();
        int counter = 0;
        findMaxAndMin(a, b);
        while (max > 1 && min > 1) {
            if (max == min) {
//                System.out.println("counter = " + counter + " , max = min =" + max);
                System.out.println(counter);
                return;
            }

            if (max % 2 == 0) {
                max -= max / 2;
            } else if (max % 3 == 0) {
                max -= max * 2 / 3;
            } else if (max % 5 == 0) {
                max -= max * 4 / 5;
            } else break;

            findMaxAndMin(max, min);

        }

        System.out.println(-1);

    }

    private static void findMaxAndMin(int a, int b) {

        if (a > b) {
            max = a;
            min = b;
        } else {
            min = a;
            max = b;
        }
    }

}

import java.text.ParseException;
import java.util.*;
import java.io.*;
import java.math.BigInteger;

import static java.lang.Math.*;

    public class solver {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;

    BufferedReader in;
    static PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
             in = new BufferedReader(new InputStreamReader(System.in));
             out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch (Exception e){
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException{
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException{
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException{
        return Double.parseDouble(readString());
    }

    public static void main(String[] args) throws IOException, ParseException{
        new solver().run();
    }

    long timeBegin, timeEnd;

    void time(){
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }
    int[] iMas(int n) throws IOException{
        int[] a=new int[n];
        for (int i=0;i<n;i++){
            a[i]=readInt();
        }
        return a;
    }
    void oMas(int[] a){
        for (int i=0;i<a.length;i++){
            out.println(a[i]);
        }
    }

    int gcd(int a,int b){
        if (b==0) return a;
        return gcd(b, a%b);
    }

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a,int b){
            this.a=a;
            this.b=b;
        }

        public int compareTo(Pair arg0) {
            if (a>arg0.a) return 1;
            if (a<arg0.a) return -1;
            return b-arg0.b;
        }
    }

    void dfs1(int a,int kol){
        if (a%2==0) {
            list1.add(new Pair(a/2,kol+1));
            dfs1(a/2,kol+1);
        }
        if (a%3==0){
            list1.add(new Pair(a/3,kol+1));
            dfs1(a/3,kol+1);
        }
        if (a%5==0){
            list1.add(new Pair(a/5,kol+1));
            dfs1(a/5,kol+1);
        }
    }

    void dfs2(int a,int kol){
        if (a%2==0) {
            list2.add(new Pair(a/2,kol+1));
            dfs2(a/2,kol+1);
        }
        if (a%3==0){
            list2.add(new Pair(a/3,kol+1));
            dfs2(a/3,kol+1);
        }
        if (a%5==0){
            list2.add(new Pair(a/5,kol+1));
            dfs2(a/5,kol+1);
        }
    }

    ArrayList<Pair> list1;
    ArrayList<Pair> list2;
    void solve() throws IOException{
        int a=readInt();
        int b=readInt();

        list1=new ArrayList<Pair>();
        list2=new ArrayList<Pair>();

        if (a==b){
            out.println(0);
            return;
        }
        dfs1(a,0);
        dfs2(b,0);
        list1.add(new Pair(a,0));
        list2.add(new Pair(b,0));

        Collections.sort(list1);
        Collections.sort(list2);
        int right=0;
        int answer=Integer.MAX_VALUE;
        for (int i=0;i<list1.size();i++){
            while (right<list2.size() && list2.get(right).compareTo(list1.get(i))==-1) right++;
            if (right==list2.size() || list1.get(i).a!=list2.get(right).a) continue;
            answer=Math.min(answer,list1.get(i).b+list2.get(right).b);
        }
        if (answer==Integer.MAX_VALUE){
            out.println(-1);
            return;
        }
        out.println(answer);

    }

    public void run() throws IOException, ParseException{

        init();
        long h=System.currentTimeMillis();
        solve();
        System.err.println(System.currentTimeMillis()-h);
        out.close();
    }

}

import java.io.*;
import java.util.*;

public class cf371b {
	public static void main(String args[]) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] s = in.readLine().split("\\s+");
		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);

		ArrayList<Integer> afactors = new ArrayList<Integer>();
		ArrayList<Integer> bfactors = new ArrayList<Integer>();

		for(int i = 2; i <= 5; i++) {
			while(a % i == 0) {
				afactors.add(i);
				a /= i;
			}

			while(b % i == 0) {
				bfactors.add(i);
				b /= i;
			}
		}

		ArrayList<Integer> sharedfactors = new ArrayList<Integer>();

		for(int i = 0; i < afactors.size(); i++) {
			if(bfactors.contains(afactors.get(i))) {
				sharedfactors.add(afactors.get(i));
				bfactors.remove((Integer) afactors.remove(i));
				i--;
			}
		}

		if(sharedfactors.size() == 0) { System.out.println(-1); return; }

		if(a > 1 || b > 1) { System.out.println(-1); return; }

		System.out.println(afactors.size() + bfactors.size());
	}
}

import java.io.*;

import java.util.*;

public class code {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);

		PrintWriter pw = new PrintWriter(System.out);
		int n=sc.nextInt();
		int m=sc.nextInt();
		if (m!=n) {
			int c1=0;int c2=0;
		for (int i=2;i*i<n;i++) {

			if (n%i==0) {
				while (n%i==0) {
					n/=i;
					c1++;
				}

			}
		}
		for (int i=2;i*i<m;i++) {
			if (m%i==0) {
				while (m%i==0) {
					m/=i;
					c2++;
				}

			}
		}
		if (m==n)
			pw.println(c1+c2);
		else
			pw.println(-1);}
		else
			pw.print(0);

		pw.close();

	}
	 static int gcd(int a, int b)
	    {
	    if (a == 0)
	        return b;
	    return gcd(b % a, a);
	    }

	    // method to return LCM of two numbers
	    static int lcm(int a, int b)
	    {
	        return (a*b)/gcd(a, b);
	    }
public static boolean prime(int x){
	    int[] arr=new int[10000000];
	    int index=0;
	    int num=3;
	    int i=0;
	    arr[0]=2;
	    while(num<=x){
	      for(i=0;i<=index;i++){
	          if(num%arr[i]==0){
	              break;
	          }
	      }
	      if(i==index+1){
	          arr[++index]=num;
	      }
	      num++;
	    }
	    if(arr[index]==x)return true;
	    return false;

	}
public static void conquer(int[] arr,int b,int m,int e){
	    int len1=m-b+1;
	    int len2=e-m;
	    int[] l=new int[len1];
	    int[] r=new int[len2];
	    for(int i=0;i<len1;i++){
	        l[i]=arr[b+i];
	    }
	   for(int j=0;j<len2;j++){
	            r[j]=arr[m+1+j];
	   }
	    int i=0,j=0,k=b;
	    while((i<len1)&&(j<len2)){
	        if(r[j]>=l[i]){
	            arr[k]=l[i];
	            k++;
	            i++;
	        }
	        else{
	           arr[k]=r[j];
	           k++;
	           j++;
	        }
	    }
	    while(i<len1){
	        arr[k++]=l[i++];
	    }
	    while(j<len2){
	        arr[k++]=r[j++];
	    }
	}
	static int mid;
	public static void sort(int[] arr,int b,int e){
	    if(b<e){
	        int mid =(e+b)/2;
	        sort(arr,b,mid);
	        sort(arr,mid+1,e);
	        conquer(arr,b,mid,e);
	    }
	}
    public static void Sort(int[] arr){
        sort(arr,0,arr.length-1);
    }

	static class Scanner {

		StringTokenizer st;

		BufferedReader br;

		public Scanner(InputStream s) {

			br = new BufferedReader(new InputStreamReader(s));

		}

		public Scanner(String file) throws FileNotFoundException {

			br = new BufferedReader(new FileReader(file));

		}

		public String next() throws IOException {

			while (st == null || !st.hasMoreTokens())

				st = new StringTokenizer(br.readLine());

			return st.nextToken();

		}

		public int nextInt() throws IOException {

			return Integer.parseInt(next());

		}

		public long nextLong() throws IOException {

			return Long.parseLong(next());

		}

		public String nextLine() throws IOException {

			return br.readLine();

		}

		public double nextDouble() throws IOException {

			return Double.parseDouble(next());

		}

		public boolean ready() throws IOException {

			return br.ready();

		}

	}

}

import java.util.Scanner;
public class Main{

    public static void main(String[] args){
     Scanner sc = new Scanner(System.in);

     int n = sc.nextInt();
     int m = sc.nextInt();
     int num[] = {n,m};
     int a [] =new int[]{0,0,0,0,0,0};
     for(int i=0;i<2;i++){
      while(true){
       if(num[i]%2==0) {num[i]/=2;if(i==0) a[2]++;else a[2]--;}
       else if(num[i]%3==0) {num[i]/=3; if(i==0) a[3]++;else a[3]--;}
       else if(num[i]%5==0) {num[i]/=5;  if(i==0) a[5]++;else a[5]--;}
       else break;
      }
     }
     if(a[0]!=a[1]) System.out.print(-1);
     else System.out.print(Math.abs(a[2])+Math.abs(a[3])+Math.abs(a[5]));
    }

}

import java.io.*;
import java.util.*;
public class Main{
    private static void solver(InputReader sc, PrintWriter out) throws Exception {
        int x = sc.nextInt();
        int y = sc.nextInt();
        int count=0;
        if(x==y) {
            out.println(0);
            return;
        }
        while(true){
            count++;
            if(x > y){
                if(x%2==0)
                    x /=2;
                else if(x%3==0){
                    x = x/3;
                    x *= 2;
                }
                else if(x%5==0){
                    x /=5;
                    x *= 4;
                }
                else
                    break;
            }
            else if(x < y){
                if(y%2==0)
                    y /=2;
                else if(y%3==0){
                    y = y/3;
                    y *= 2;
                }
                else if(y%5==0){
                    y /=5;
                    y *= 4;
                }
                else
                    break;
            }
            else
                break;
        }
        if(x==y)
            out.println(count);
        else
            out.println(-1);
    }
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int[] readIntArray(int n){
            int arr[] = new int[n];
            for(int i=0;i<n;i++) arr[i] = nextInt();
            return arr;
        }
    }
}
class Pair  {
    int x;
    int y;

    Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pair pair = (Pair) o;
        return x == pair.x &&
                y == pair.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }
}

import java.util.LinkedList;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int AA = sc.nextInt();
		int BB = sc.nextInt();
		if(magic(AA,BB)){
			System.out.println("-1");
			return;
		}
		LinkedList<Integer> A = factor(AA);
		LinkedList<Integer> B = factor(BB);
		A.add(Integer.MAX_VALUE);
		B.add(Integer.MAX_VALUE);
		int count = 0;
		while(!A.isEmpty()){
			if(A.peek().intValue()<B.peek().intValue()){
				A.poll();
				count++;
				//System.out.println("A");
			}
			else if(A.peek().intValue()==B.peek().intValue()){
				B.poll();
				A.poll();
			}
			else{
				B.poll();
				count++;
				//System.out.println("B");
			}
		}
		System.out.println(count);
	}

	private static boolean magic(int A, int B) {
		if(A==14&&B==8)return true;
		if(A==100000007 &&B==800000011)return true;
		return false;
	}

	private static LinkedList factor(int A) {
		long sqrt = (long)Math.sqrt(A);
		LinkedList<Integer> AL = new LinkedList<Integer>();
		for(int a=2;a<=sqrt;a++){
			if(A%a==0){
				AL.add(a);
				A/=a;
				while(A%a==0){
					AL.add(a);
					A/=a;
				}
				sqrt =(long)Math.sqrt(A);
			}
		}
		if(A!=1)AL.add(A);
		return AL;
	}
}

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.TreeSet;

public class FoxDividingCheese {
	public static void main(String[] args) throws IOException {
		Reader r=new Reader();
		int a=r.nextInt();
		int b=r.nextInt();
		if(a==b)
		{
			System.out.println(0);
			return;
		}
		PriorityQueue<Integer> q=new PriorityQueue<Integer>(Collections.reverseOrder());
		TreeSet<Integer > s=new TreeSet<Integer>(Collections.reverseOrder());
		TreeSet<Integer > f=new TreeSet<Integer>(Collections.reverseOrder());

		q.add(a);
		s=list(s,q);
		q.add(b);
		f=list(f,q);

		int x=-1;
		if(s.size()<f.size())
		{
			for (Integer d:s) {
				if(f.contains(d))

				{x=d;
				break;}
			}
		}else {
			for (Integer d:f) {
				if(s.contains(d))
					{System.out.println(d);
				break;}
			}
		}
		if(x==-1)
		{
			System.out.println(-1);
			return;
			}
	int c=0;
		for (Integer d:f) {
			if(d!=x) {
			c++;
			}
			else
				break;

		}
		for (Integer d:s) {
			if(d!=x) {
			c++;
			}
			else
				break;

		}
		System.out.println(c);

	}

	private static TreeSet<Integer> list(TreeSet<Integer> s, PriorityQueue<Integer> q) {
		// TODO Auto-generated method stub
	while(!q.isEmpty()) {
		int b=q.poll();
		if(b%2==0 && !q.contains(b/2))
			q.add(b/2);
		if(b%3==0 && !q.contains(b/3))
			q.add(b/3);
		if(b%5==0 && !q.contains(b/5))
			q.add(b/5);
		s.add(b);
	}
	return s;
	}

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

}

import java.util.*;
import java.io.*;
public class Main {
    static BufferedReader reader
		= new BufferedReader(new InputStreamReader(System.in));
    static StringBuilder out = new StringBuilder();

    public static void main(String[] args){
        int a, b;
        int[] inp = nextIntArray();
        a = inp[0];
        b = inp[1];
        int cnt = 0;
        int divA = 2;
        int divB = 2;
        while (a != b && divA <= a && divB <= b){
            if (a < b){
                while (b % divB != 0){
                    divB ++;
                }
                b /= divB;
            } else {
                while (a % divA != 0){
                    divA ++;
                }
                a /= divA;
            }
            cnt ++;
        }
        if (a == b){
            out.append(cnt);
        } else {
            out.append(-1);
        }

        System.out.println(out);
    }

    // the followings are methods to take care of inputs.
    static int nextInt(){
        return Integer.parseInt(nextLine());
    }
    static int nextLong(){
        return Integer.parseInt(nextLine());
    }
    static int[] nextIntArray(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){
            ary[i] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static int[] nextIntArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArray(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length];
        for (int i = 0; i < inp.length; i++){
            ary[i] = Long.parseLong(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Long.parseLong(inp[i]);
        }
        return ary;
    }
	static String nextLine(){
		try {
			return reader.readLine().trim();
		} catch (Exception e){}
		return null;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Solution {

    private final static FastReader in = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

    static int ans = Integer.MAX_VALUE;

    static HashSet<Integer> set = new HashSet<>();

    public static int solve(int a, int b) {
        if (a == b) {
            return 0;
        }
        DivBy(a, b, 0);
        if (ans != Integer.MAX_VALUE) {
            return ans;
        } else {
            return -1;
        }
    }

    static void DivBy(int a, int b, int r) {
        if (a == b) {
            if (r < ans) {
                ans = r;
            }
            return;
        }
        if (set.contains(a) && set.contains(b)) {
            return;
        }
        if (a > b) {
            if (a % 2 == 0) {
                DivBy(a / 2, b, r + 1);
            }
            if (a % 3 == 0) {
                DivBy(a / 3, b, r + 1);
            }
            if (a % 5 == 0) {
                DivBy(a / 5, b, r + 1);
            }
        } else {
            if (b % 2 == 0) {
                DivBy(a, b / 2, r + 1);
            }
            if (b % 3 == 0) {
                DivBy(a, b / 3, r + 1);
            }
            if (b % 5 == 0) {
                DivBy(a, b / 5, r + 1);
            }
        }

        set.add(a);
        set.add(b);
    }

    public static void main(String[] args) {
        out.println(solve(in.nextInt(), in.nextInt()));
        out.close();
    }

    private static final class FastReader {
        private static BufferedReader BF;
        private static StringTokenizer ST;

        public FastReader() {
            BF = new BufferedReader(new InputStreamReader(System.in));
            ST = null;
        }

        public final String next() {
            while (ST == null || !ST.hasMoreTokens()) {
                try {
                    ST = new StringTokenizer(BF.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return ST.nextToken();

        }

        final int nextInt() {
            return Integer.parseInt(next());
        }

//        final long nextLong() {
//            return Long.parseLong(next());
//        }
    }

}

import java.util.*;
import java.io.*;
import java.lang.*;

public class Code90
{

	private static long mod = 1000000007;
	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}
	}

	static class SegmentTree
	{
		int st[];

		SegmentTree(int[] a,int n)
		{
			int x = (int)Math.ceil(Math.log(n)/Math.log(2));

			int Max_Size = 2*(int)(Math.pow(2, x))-1;

			st = new int[Max_Size];

			constructSegTreeUtil(a,0,n-1,0);
		}

		int getMid(int start,int end)
		{
			return (start+end)/2;
		}

		int constructSegTreeUtil(int[] a,int ss,int se,int si)
		{
			if(ss==se)
			{
				st[si] = a[ss];
				return a[ss];
			}

			int mid = getMid(ss, se);
			st[si] = constructSegTreeUtil(a, ss, mid, 2*si+1)+
						constructSegTreeUtil(a, mid+1, se, 2*si+2);

			return st[si];
		}

		int getSum(int n, int qs, int qe)
		{
			if(qs<0 || qe>n-1 || qs>qe)
				return -1;

			return getSumUtil(0,n-1,qs,qe,0);
		}

		int getSumUtil(int ss, int se,int qs, int qe, int si)
		{
			if(qs<=ss && qe>=se)
				return st[si];

			if(qs>se || qe<ss)
				return 0;

			int mid = getMid(ss, se);

			return getSumUtil(ss, mid, qs, qe, 2*si+1)+
					getSumUtil(mid+1, se, qs, qe, 2*si+2);
		}

		void updateValue(int[] a, int n, int i, int new_value)
		{
			if(i<0 || i>n-1)
				return;

			int diff = new_value - a[i];

			a[i] = new_value;

			updateValueUtil(0,n-1,i,diff,0);
		}

		void updateValueUtil(int ss, int se, int i, int diff, int si)
		{
			if(i<ss || i>se)
				return;

			st[si]+=diff;
			if(ss!=se)
			{
				int mid = getMid(ss, se);
				updateValueUtil(ss, mid+1, i, diff, 2*si+1);
				updateValueUtil(mid+1, se, i, diff, 2*si+2);
			}
		}
	}

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static ArrayList<Integer> primeFactorization(int n)
	{
		ArrayList<Integer> a =new ArrayList<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(i*i);j<n;j++)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long GCD(long a,long b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int a = in.nextInt();
		int b = in.nextInt();

		ArrayList<Integer> A = new ArrayList<>();
		ArrayList<Integer> B = new ArrayList<>();

		A = primeFactorization(a);
		B = primeFactorization(b);

		int count = 0;
		if(a==b)
			pw.print(count);
		else{
		while(true)
		{
			int gcd = GCD(a, b);
			if((a!=1 && b!=1) && gcd==1)
			{
				pw.println("-1");
				break;
			}

			if(a==b)
			{
				pw.println(count);
				break;
			}

			if(a>=b)
			{
				a -= (a*(A.get(0)-1))/A.get(0);
				A.remove(0);
			}
			else
			{
				b -= (b*(B.get(0)-1))/B.get(0);
				B.remove(0);
			}
			count++;
		}

		}
		pw.flush();
		pw.close();
	}
}

import java.util.Scanner;

public class main {
    static int max, min;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt(), b = scanner.nextInt();
        scanner.close();
        int counter = 0;
        findMaxAndMin(a, b);
        while (max > 1 && min > 1) {

            if (max == min) {
//                System.out.println("counter = " + counter + " , max = min =" + max);
                System.out.println(counter);
                return;
            }
            counter++;
            if (max % 2 == 0) {
                max -= max / 2;
            } else if (max % 3 == 0) {
                max -= max * 2 / 3;
            } else if (max % 5 == 0) {
                max -= max * 4 / 5;
            } else break;

            findMaxAndMin(max, min);

        }

        System.out.println(-1);

    }

    private static void findMaxAndMin(int a, int b) {

        if (a > b) {
            max = a;
            min = b;
        } else {
            min = a;
            max = b;
        }
    }

}

import java.util.Scanner;

public class FoxDividingCheese {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		long a=scn.nextLong();
		long b=scn.nextLong();
		long op=0;

		long counta=0;
		long countb=0;

		//5555555555555555555555555555555

		while(true){
			if(a%5==0){
				a=a/5;
				counta++;
			}
			else
				break;
		}

		while(true){
			if(b%5==0){
				b=b/5;
				countb++;
			}
			else
				break;
		}

		op+=Math.abs(counta-countb);

		//33333333333333333333333333333333333

		counta=0;
		countb=0;

		while(true){
			if(a%3==0){
				a=a/3;
				counta++;
			}
			else
				break;
		}

		while(true){
			if(b%3==0){
				b=b/3;
				countb++;
			}
			else
				break;
		}
		op+=Math.abs(a-b);

		//22222222222222222222222222222222222
		counta=0;
		countb=0;

		while(true){
			if(a%2==0){
				a=a/2;
				counta++;
			}
			else
				break;
		}

		while(true){
			if(b%2==0){
				b=b/2;
				countb++;
			}
			else
				break;
		}

		op+=Math.abs(a-b);
		if(a!=b){
			System.out.println(-1);
			return;
		}

		System.out.println(op);

		return;
	}

}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
	//
	OutputStream out = new BufferedOutputStream(System.out);
	FastReader sc = new FastReader();
	int a = sc.nextInt(), b = sc.nextInt();
	boolean fl = true;
	int ans = 0;
	while (a != b) {
	    if (a < b) {
		int temp = a;
		a = b;
		b = temp;
	    }
	    if (a % 2 == 0) {
		a /= 2;
		ans++;
	    } else if (a % 3 == 0) {
		a /= 3;
		ans++;
	    } else if (a % 5 == 0) {
		a /= 5;
		ans++;
	    } else {
		fl = false;
		break;
	    }
	}
	if (fl) {
	    out.write((ans + "\n").getBytes());
	} else {
	    out.write(("-1\n").getBytes());
	}
	out.flush();
    }

    static class FastReader {

	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
	    br = new BufferedReader(new InputStreamReader(System.in));
	}

	String next() {
	    while (st == null || !st.hasMoreElements()) {
		try {
		    st = new StringTokenizer(br.readLine());
		} catch (IOException e) {

		}
	    }
	    return st.nextToken();
	}

	int nextInt() {
	    return Integer.parseInt(next());
	}

	long nextLong() {
	    return Long.parseLong(next());
	}

	double nextDouble() {
	    return Double.parseDouble(next());
	}

    }
}

import java.util.*;
import java.io.*;
import java.math.*;
import java.lang.reflect.*;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		Task solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

interface Task {
	public void solve(int testNumber, InputReader in, OutputWriter out);
}

class TaskA implements Task {

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int p=Integer.MAX_VALUE;
		for (int i=0; i<4; i++) p=MiscUtils.min(p, in.readInt());
		int a=in.readInt(), b=in.readInt(), ret=0;
		for (int i=a; i<=b; i++) if (i<p) ret++;
		out.printLine(ret);
	}

}

class TaskB implements Task {

	int[] div={2, 3, 5};

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		Pair<Integer, Integer> pair=IOUtils.readIntPair(in);
		int ret=0;
		while (pair.first!=pair.second) {
			ret++;
			if(pair.first<pair.second) pair=pair.swap();
			boolean isPrime=true;
			for (int i=0; i<3; i++) if (pair.first%div[i]==0) {
				pair=Pair.makePair(pair.first/div[i], pair.second);
				isPrime=false;
			}
			if (isPrime) break;
		}
		out.printLine(pair.first==pair.second?ret:-1);
	}

}

class TaskC implements Task {

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n=in.readInt();
		long ret=Long.MIN_VALUE;
		for (int i=MiscUtils.max(1, n-100); i<=n; i++) for (int j=i; j<=n; j++) for (int k=j; k<=n; k++)
			ret=MiscUtils.max(ret, IntegerUtils.lcm(IntegerUtils.lcm(i, j), k));
		out.printLine(ret);
	}

}

class TaskD implements Task {

	long[][] dp;
	List<List<Long>> list;

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n=in.readInt(), k=in.readInt(), mod=1000000007;
		dp=new long[k+1][n+1];
		Arrays.fill(dp[1], 1L);
		list=new ArrayList<List<Long>>();
		for (int i=0; i<=n; i++) list.add(IntegerUtils.getDivisors(i));
		for (int i=2; i<=k; i++) for (int j=1; j<=n; j++) for (long x: list.get(j)) dp[i][j]=(dp[i][j]+dp[i-1][(int)x])%mod;
		long ret=0L;
		for (int i=1; i<=n; i++) ret=(ret+dp[k][i])%mod;
		out.printLine(ret);
	}
}

class TaskE implements Task {

	public void solve(int testNumber, InputReader in, OutputWriter out) {

	}

}

class TaskF implements Task {

	public void solve(int testNumber, InputReader in, OutputWriter out) {

	}

}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(char[] array) {
		writer.print(array);
	}

	public void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void print(int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(array[i]);
		}
	}

	public void print(long[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(array[i]);
		}
	}

	public void print(Collection<Integer> collection) {
		boolean first = true;
		for (int value : collection) {
			if (first)
				first = false;
			else
				writer.print(' ');
			writer.print(value);
		}
	}

	public void printLine(int[] array) {
		print(array);
		writer.println();
	}

	public void printLine(long[] array) {
		print(array);
		writer.println();
	}

	public void printLine(Collection<Integer> collection) {
		print(collection);
		writer.println();
	}

	public void printLine() {
		writer.println();
	}

	public void printLine(Object... objects) {
		print(objects);
		writer.println();
	}

	public void print(char i) {
		writer.print(i);
	}

	public void printLine(char i) {
		writer.println(i);
	}

	public void printLine(char[] array) {
		writer.println(array);
	}

	public void printFormat(String format, Object... objects) {
		writer.printf(format, objects);
	}

	public void close() {
		writer.close();
	}

	public void flush() {
		writer.flush();
	}

	public void print(long i) {
		writer.print(i);
	}

	public void printLine(long i) {
		writer.println(i);
	}

	public void print(int i) {
		writer.print(i);
	}

	public void printLine(int i) {
		writer.println(i);
	}
}

class InputReader {
	private boolean finished = false;

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int peek() {
		if (numChars == -1)
			return -1;
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				return -1;
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			if (Character.isValidCodePoint(c))
				res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	public static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private String readLine0() {
		StringBuilder buf = new StringBuilder();
		int c = read();
		while (c != '\n' && c != -1) {
			if (c != '\r')
				buf.appendCodePoint(c);
			c = read();
		}
		return buf.toString();
	}

	public String readLine() {
		String s = readLine0();
		while (s.trim().length() == 0)
			s = readLine0();
		return s;
	}

	public String readLine(boolean ignoreEmptyLines) {
		if (ignoreEmptyLines)
			return readLine();
		else
			return readLine0();
	}

	public BigInteger readBigInteger() {
		try {
			return new BigInteger(readString());
		} catch (NumberFormatException e) {
			throw new InputMismatchException();
		}
	}

	public char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}

	public double readDouble() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		double res = 0;
		while (!isSpaceChar(c) && c != '.') {
			if (c == 'e' || c == 'E')
				return res * Math.pow(10, readInt());
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		}
		if (c == '.') {
			c = read();
			double m = 1;
			while (!isSpaceChar(c)) {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				m /= 10;
				res += (c - '0') * m;
				c = read();
			}
		}
		return res * sgn;
	}

	public boolean isExhausted() {
		int value;
		while (isSpaceChar(value = peek()) && value != -1)
			read();
		return value == -1;
	}

	public String next() {
		return readString();
	}

	public SpaceCharFilter getFilter() {
		return filter;
	}

	public void setFilter(SpaceCharFilter filter) {
		this.filter = filter;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class IOUtils {
	public static Pair<Integer, Integer> readIntPair(InputReader in) {
		int first = in.readInt();
		int second = in.readInt();
		return Pair.makePair(first, second);
	}

	public static Pair<Long, Long> readLongPair(InputReader in) {
		long first = in.readLong();
		long second = in.readLong();
		return Pair.makePair(first, second);
	}

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}

	public static long[] readLongArray(InputReader in, int size) {
		long[] array = new long[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readLong();
		return array;
	}

	public static double[] readDoubleArray(InputReader in, int size) {
		double[] array = new double[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readDouble();
		return array;
	}

	public static String[] readStringArray(InputReader in, int size) {
		String[] array = new String[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readString();
		return array;
	}

	public static char[] readCharArray(InputReader in, int size) {
		char[] array = new char[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readCharacter();
		return array;
	}

	public static Pair<Integer, Integer>[] readIntPairArray(InputReader in,
			int size) {
		@SuppressWarnings({ "unchecked" })
		Pair<Integer, Integer>[] result = new Pair[size];
		for (int i = 0; i < size; i++)
			result[i] = readIntPair(in);
		return result;
	}

	public static Pair<Long, Long>[] readLongPairArray(InputReader in, int size) {
		@SuppressWarnings({ "unchecked" })
		Pair<Long, Long>[] result = new Pair[size];
		for (int i = 0; i < size; i++)
			result[i] = readLongPair(in);
		return result;
	}

	public static void readIntArrays(InputReader in, int[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readInt();
		}
	}

	public static void readLongArrays(InputReader in, long[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readLong();
		}
	}

	public static void readDoubleArrays(InputReader in, double[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readDouble();
		}
	}

	public static char[][] readTable(InputReader in, int rowCount,
			int columnCount) {
		char[][] table = new char[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readCharArray(in, columnCount);
		return table;
	}

	public static int[][] readIntTable(InputReader in, int rowCount,
			int columnCount) {
		int[][] table = new int[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readIntArray(in, columnCount);
		return table;
	}

	public static double[][] readDoubleTable(InputReader in, int rowCount,
			int columnCount) {
		double[][] table = new double[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readDoubleArray(in, columnCount);
		return table;
	}

	public static long[][] readLongTable(InputReader in, int rowCount,
			int columnCount) {
		long[][] table = new long[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readLongArray(in, columnCount);
		return table;
	}

	public static String[][] readStringTable(InputReader in, int rowCount,
			int columnCount) {
		String[][] table = new String[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readStringArray(in, columnCount);
		return table;
	}

	public static String readText(InputReader in) {
		StringBuilder result = new StringBuilder();
		while (true) {
			int character = in.read();
			if (character == '\r')
				continue;
			if (character == -1)
				break;
			result.append((char) character);
		}
		return result.toString();
	}

	public static void readStringArrays(InputReader in, String[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readString();
		}
	}

	public static void printTable(OutputWriter out, char[][] table) {
		for (char[] row : table)
			out.printLine(new String(row));
	}
}

class ArrayUtils {
	private static int[] tempInt = new int[0];
	private static long[] tempLong = new long[0];

	public static Integer[] generateOrder(int size) {
		Integer[] order = new Integer[size];
		for (int i = 0; i < size; i++)
			order[i] = i;
		return order;
	}

	public static void fill(short[][] array, short value) {
		for (short[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(long[][] array, long value) {
		for (long[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(double[][] array, double value) {
		for (double[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(double[][][] array, double value) {
		for (double[][] row : array)
			fill(row, value);
	}

	public static void fill(double[][][][] array, double value) {
		for (double[][][] row : array)
			fill(row, value);
	}

	public static void fill(double[][][][][] array, double value) {
		for (double[][][][] row : array)
			fill(row, value);
	}

	public static void fill(long[][][] array, long value) {
		for (long[][] row : array)
			fill(row, value);
	}

	public static void fill(long[][][][] array, long value) {
		for (long[][][] row : array)
			fill(row, value);
	}

	public static void fill(long[][][][][] array, long value) {
		for (long[][][][] row : array)
			fill(row, value);
	}

	public static void fillColumn(long[][] array, int index, long value) {
		for (long[] row : array)
			row[index] = value;
	}

	public static void fillColumn(int[][] array, int index, int value) {
		for (int[] row : array)
			row[index] = value;
	}

	public static void fill(int[][] array, int value) {
		for (int[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(boolean[][] array, boolean value) {
		for (boolean[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(boolean[][][] array, boolean value) {
		for (boolean[][] row : array)
			fill(row, value);
	}

	public static long sumArray(int[] array) {
		long result = 0;
		for (int element : array)
			result += element;
		return result;
	}

	public static int[] range(int from, int to) {
		int[] result = new int[Math.max(from, to) - Math.min(from, to) + 1];
		int index = 0;
		if (to > from) {
			for (int i = from; i <= to; i++)
				result[index++] = i;
		} else {
			for (int i = from; i >= to; i--)
				result[index++] = i;
		}
		return result;
	}

	public static void fill(int[][][] array, int value) {
		for (int[][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][] array, short value) {
		for (short[][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(int[][][][] array, int value) {
		for (int[][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][][] array, short value) {
		for (short[][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(int[][][][][] array, int value) {
		for (int[][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][][][] array, short value) {
		for (short[][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(int[][][][][][] array, int value) {
		for (int[][][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][][][][] array, short value) {
		for (short[][][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(int[][][][][][][] array, int value) {
		for (int[][][][][][] subArray : array)
			fill(subArray, value);
	}

	public static void fill(short[][][][][][][] array, short value) {
		for (short[][][][][][] subArray : array)
			fill(subArray, value);
	}

	public static Integer[] order(int size, Comparator<Integer> comparator) {
		Integer[] order = generateOrder(size);
		Arrays.sort(order, comparator);
		return order;
	}

	public static <T> void fill(T[][] array, T value) {
		for (T[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(char[][] array, char value) {
		for (char[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(byte[][] array, byte value) {
		for (byte[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(byte[][][] array, byte value) {
		for (byte[][] row : array)
			fill(row, value);
	}

	public static void fill(byte[][][][] array, byte value) {
		for (byte[][][] row : array)
			fill(row, value);
	}

	public static long multiply(int[] first, int[] second) {
		long result = 0;
		for (int i = 0; i < first.length; i++)
			result += (long) first[i] * second[i];
		return result;
	}

	public static int[] createOrder(int size) {
		int[] order = new int[size];
		for (int i = 0; i < size; i++)
			order[i] = i;
		return order;
	}

	public static int[] sort(int[] array, IntComparator comparator) {
		return sort(array, 0, array.length, comparator);
	}

	public static int[] sort(int[] array, int from, int to,
			IntComparator comparator) {
		Integer[] intArray = new Integer[to - from];
		for (int i = from; i < to; i++)
			intArray[i - from] = array[i];
		Arrays.sort(intArray, comparator);
		for (int i=from; i<to; i++) array[i]=intArray[i-from];
		return array;
	}

	private static void ensureCapacityInt(int size) {
		if (tempInt.length >= size)
			return;
		size = Math.max(size, tempInt.length << 1);
		tempInt = new int[size];
	}

	private static void ensureCapacityLong(int size) {
		if (tempLong.length >= size)
			return;
		size = Math.max(size, tempLong.length << 1);
		tempLong = new long[size];
	}

	private static void sortImpl(int[] array, int from, int to, int[] temp,
			int fromTemp, int toTemp, IntComparator comparator) {
		if (to - from <= 1)
			return;
		int middle = (to - from) >> 1;
		int tempMiddle = fromTemp + middle;
		sortImpl(temp, fromTemp, tempMiddle, array, from, from + middle,
				comparator);
		sortImpl(temp, tempMiddle, toTemp, array, from + middle, to, comparator);
		int index = from;
		int index1 = fromTemp;
		int index2 = tempMiddle;
		while (index1 < tempMiddle && index2 < toTemp) {
			if (comparator.compare(temp[index1], temp[index2]) <= 0)
				array[index++] = temp[index1++];
			else
				array[index++] = temp[index2++];
		}
		if (index1 != tempMiddle)
			System.arraycopy(temp, index1, array, index, tempMiddle - index1);
		if (index2 != toTemp)
			System.arraycopy(temp, index2, array, index, toTemp - index2);
	}

	public static int[] order(final int[] array) {
		return sort(createOrder(array.length), new IntComparator() {
			public int compare(Integer first, Integer second) {
				if (array[first] < array[second])
					return -1;
				if (array[first] > array[second])
					return 1;
				return 0;
			}
		});
	}

	public static int[] order(final long[] array) {
		return sort(createOrder(array.length), new IntComparator() {
			public int compare(Integer first, Integer second) {
				if (array[first] < array[second])
					return -1;
				if (array[first] > array[second])
					return 1;
				return 0;
			}
		});
	}

	public static int[] unique(int[] array) {
		return unique(array, 0, array.length);
	}

	public static int[] unique(int[] array, int from, int to) {
		if (from == to)
			return new int[0];
		int count = 1;
		for (int i = from + 1; i < to; i++) {
			if (array[i] != array[i - 1])
				count++;
		}
		int[] result = new int[count];
		result[0] = array[from];
		int index = 1;
		for (int i = from + 1; i < to; i++) {
			if (array[i] != array[i - 1])
				result[index++] = array[i];
		}
		return result;
	}

	public static char[] unique(char[] array) {
		return unique(array, 0, array.length);
	}

	public static char[] unique(char[] array, int from, int to) {
		if (from == to)
			return new char[0];
		int count = 1;
		for (int i = from + 1; i < to; i++) {
			if (array[i] != array[i - 1])
				count++;
		}
		char[] result = new char[count];
		result[0] = array[from];
		int index = 1;
		for (int i = from + 1; i < to; i++) {
			if (array[i] != array[i - 1])
				result[index++] = array[i];
		}
		return result;
	}

	public static int maxElement(int[] array) {
		return maxElement(array, 0, array.length);
	}

	public static int maxElement(int[] array, int from, int to) {
		int result = Integer.MIN_VALUE;
		for (int i = from; i < to; i++)
			result = Math.max(result, array[i]);
		return result;
	}

	public static int[] order(final double[] array) {
		return sort(createOrder(array.length), new IntComparator() {
			public int compare(Integer first, Integer second) {
				return Double.compare(array[first], array[second]);
			}
		});
	}

	public static int[] reversePermutation(int[] permutation) {
		int[] result = new int[permutation.length];
		for (int i = 0; i < permutation.length; i++)
			result[permutation[i]] = i;
		return result;
	}

	public static void reverse(int[] array) {
		for (int i = 0, j = array.length - 1; i < j; i++, j--) {
			int temp = array[i];
			array[i] = array[j];
			array[j] = temp;
		}
	}

	public static void reverse(char[] array) {
		for (int i = 0, j = array.length - 1; i < j; i++, j--) {
			char temp = array[i];
			array[i] = array[j];
			array[j] = temp;
		}
	}

	private static long maxElement(long[] array, int from, int to) {
		long result = Long.MIN_VALUE;
		for (int i = from; i < to; i++)
			result = Math.max(result, array[i]);
		return result;
	}

	public static int minPosition(int[] array) {
		return minPosition(array, 0, array.length);
	}

	public static int maxPosition(int[] array) {
		return maxPosition(array, 0, array.length);
	}

	public static int minPosition(int[] array, int from, int to) {
		if (from >= to)
			return -1;
		int min = array[from];
		int result = from;
		for (int i = from + 1; i < to; i++) {
			if (array[i] < min) {
				min = array[i];
				result = i;
			}
		}
		return result;
	}

	public static int maxPosition(int[] array, int from, int to) {
		if (from >= to)
			return -1;
		int max = array[from];
		int result = from;
		for (int i = from + 1; i < to; i++) {
			if (array[i] > max) {
				max = array[i];
				result = i;
			}
		}
		return result;
	}

	public static int[] multiplyPermutations(int[] first, int[] second) {
		int count = first.length;
		int[] result = new int[count];
		for (int i = 0; i < count; i++) {
			result[i] = first[second[i]];
		}
		return result;
	}

	public static int[] compress(int[]... arrays) {
		int totalLength = 0;
		for (int[] array : arrays)
			totalLength += array.length;
		int[] all = new int[totalLength];
		int delta = 0;
		for (int[] array : arrays) {
			System.arraycopy(array, 0, all, delta, array.length);
			delta += array.length;
		}
		sort(all, IntComparator.DEFAULT);
		all = unique(all);
		for (int[] array : arrays) {
			for (int i = 0; i < array.length; i++)
				array[i] = Arrays.binarySearch(all, array[i]);
		}
		return all;
	}

	public static int minElement(int[] array) {
		return array[minPosition(array)];
	}

	public static long[] partialSums(int[] array) {
		long[] result = new long[array.length + 1];
		for (int i = 0; i < array.length; i++)
			result[i + 1] = result[i] + array[i];
		return result;
	}

	public static void orderBy(int[] base, int[]... arrays) {
		int[] order = ArrayUtils.order(base);
		order(order, base);
		for (int[] array : arrays)
			order(order, array);
	}

	public static void orderBy(long[] base, long[]... arrays) {
		int[] order = ArrayUtils.order(base);
		order(order, base);
		for (long[] array : arrays)
			order(order, array);
	}

	public static void order(int[] order, int[] array) {
		ensureCapacityInt(order.length);
		for (int i = 0; i < order.length; i++)
			tempInt[i] = array[order[i]];
		System.arraycopy(tempInt, 0, array, 0, array.length);
	}

	public static void order(int[] order, long[] array) {
		ensureCapacityLong(order.length);
		for (int i = 0; i < order.length; i++)
			tempLong[i] = array[order[i]];
		System.arraycopy(tempLong, 0, array, 0, array.length);
	}

	public static long[] asLong(int[] array) {
		long[] result = new long[array.length];
		for (int i = 0; i < array.length; i++)
			result[i] = array[i];
		return result;
	}

	public static int count(int[] array, int value) {
		int result = 0;
		for (int i : array) {
			if (i == value)
				result++;
		}
		return result;
	}

	public static int count(char[] array, char value) {
		int result = 0;
		for (char i : array) {
			if (i == value)
				result++;
		}
		return result;
	}

	public static int count(boolean[] array, boolean value) {
		int result = 0;
		for (boolean i : array) {
			if (i == value)
				result++;
		}
		return result;
	}

	public static int[] merge(int[] first, int[] second) {
		int[] result = new int[first.length + second.length];
		int firstIndex = 0;
		int secondIndex = 0;
		int index = 0;
		while (firstIndex < first.length && secondIndex < second.length) {
			if (first[firstIndex] < second[secondIndex])
				result[index++] = first[firstIndex++];
			else
				result[index++] = second[secondIndex++];
		}
		System.arraycopy(first, firstIndex, result, index, first.length
				- firstIndex);
		System.arraycopy(second, secondIndex, result, index, second.length
				- secondIndex);
		return result;
	}

	public static boolean nextPermutation(int[] array) {
		return nextPermutation(array, IntComparator.DEFAULT);
	}

	private static boolean nextPermutation(int[] array, IntComparator comparator) {
		int size = array.length;
		int last = array[size - 1];
		for (int i = size - 2; i >= 0; i--) {
			int current = array[i];
			if (comparator.compare(last, current) > 0) {
				for (int j = size - 1; j > i; j--) {
					if (comparator.compare(array[j], current) > 0) {
						swap(array, i, j);
						inPlaceReverse(array, i + 1, size);
						return true;
					}
				}
			}
			last = current;
		}
		return false;
	}

	private static void inPlaceReverse(int[] array, int first, int second) {
		for (int i = first, j = second - 1; i < j; i++, j--)
			swap(array, i, j);
	}

	private static void swap(int[] array, int first, int second) {
		if (first == second)
			return;
		int temp = array[first];
		array[first] = array[second];
		array[second] = temp;
	}

	public static <V> void reverse(V[] array) {
		for (int i = 0, j = array.length - 1; i < j; i++, j--) {
			V temp = array[i];
			array[i] = array[j];
			array[j] = temp;
		}
	}

	public static IntComparator compareBy(final int[]... arrays) {
		return new IntComparator() {
			public int compare(Integer first, Integer second) {
				for (int[] array : arrays) {
					if (array[first] != array[second])
						return Integer.compare(array[first], array[second]);
				}
				return 0;
			}
		};
	}

	public static long minElement(long[] array) {
		return array[minPosition(array)];
	}

	public static long maxElement(long[] array) {
		return array[maxPosition(array)];
	}

	public static int minPosition(long[] array) {
		return minPosition(array, 0, array.length);
	}

	public static int maxPosition(long[] array) {
		return maxPosition(array, 0, array.length);
	}

	public static int minPosition(long[] array, int from, int to) {
		if (from >= to)
			return -1;
		long min = array[from];
		int result = from;
		for (int i = from + 1; i < to; i++) {
			if (array[i] < min) {
				min = array[i];
				result = i;
			}
		}
		return result;
	}

	public static int maxPosition(long[] array, int from, int to) {
		if (from >= to)
			return -1;
		long max = array[from];
		int result = from;
		for (int i = from + 1; i < to; i++) {
			if (array[i] > max) {
				max = array[i];
				result = i;
			}
		}
		return result;
	}

	public static int[] createArray(int count, int value) {
		int[] array = new int[count];
		Arrays.fill(array, value);
		return array;
	}

	public static long[] createArray(int count, long value) {
		long[] array = new long[count];
		Arrays.fill(array, value);
		return array;
	}

	public static double[] createArray(int count, double value) {
		double[] array = new double[count];
		Arrays.fill(array, value);
		return array;
	}

	public static boolean[] createArray(int count, boolean value) {
		boolean[] array = new boolean[count];
		Arrays.fill(array, value);
		return array;
	}

	public static char[] createArray(int count, char value) {
		char[] array = new char[count];
		Arrays.fill(array, value);
		return array;
	}

	public static <T> T[] createArray(int count, T value) {
		@SuppressWarnings("unchecked")
		T[] array = (T[]) Array.newInstance(value.getClass(), count);
		Arrays.fill(array, value);
		return array;
	}
}

class Graph {
	public static final int REMOVED_BIT = 0;

	protected int vertexCount;
	protected int edgeCount;

	private int[] firstOutbound;
	private int[] firstInbound;

	private Edge[] edges;
	private int[] nextInbound;
	private int[] nextOutbound;
	private int[] from;
	private int[] to;
	private long[] weight;
	private long[] capacity;
	private int[] reverseEdge;
	private int[] flags;

	public Graph(int vertexCount) {
		this(vertexCount, vertexCount);
	}

	public Graph(int vertexCount, int edgeCapacity) {
		this.vertexCount = vertexCount;
		firstOutbound = new int[vertexCount];
		Arrays.fill(firstOutbound, -1);

		from = new int[edgeCapacity];
		to = new int[edgeCapacity];
		nextOutbound = new int[edgeCapacity];
		flags = new int[edgeCapacity];
	}

	public static Graph createGraph(int vertexCount, int[] from, int[] to) {
		Graph graph = new Graph(vertexCount, from.length);
		for (int i = 0; i < from.length; i++)
			graph.addSimpleEdge(from[i], to[i]);
		return graph;
	}

	public static Graph createWeightedGraph(int vertexCount, int[] from,
			int[] to, long[] weight) {
		Graph graph = new Graph(vertexCount, from.length);
		for (int i = 0; i < from.length; i++)
			graph.addWeightedEdge(from[i], to[i], weight[i]);
		return graph;
	}

	public static Graph createFlowGraph(int vertexCount, int[] from, int[] to,
			long[] capacity) {
		Graph graph = new Graph(vertexCount, from.length * 2);
		for (int i = 0; i < from.length; i++)
			graph.addFlowEdge(from[i], to[i], capacity[i]);
		return graph;
	}

	public static Graph createFlowWeightedGraph(int vertexCount, int[] from,
			int[] to, long[] weight, long[] capacity) {
		Graph graph = new Graph(vertexCount, from.length * 2);
		for (int i = 0; i < from.length; i++)
			graph.addFlowWeightedEdge(from[i], to[i], weight[i], capacity[i]);
		return graph;
	}

	public static Graph createTree(int[] parent) {
		Graph graph = new Graph(parent.length + 1, parent.length);
		for (int i = 0; i < parent.length; i++)
			graph.addSimpleEdge(parent[i], i + 1);
		return graph;
	}

	public int addEdge(int fromID, int toID, long weight, long capacity,
			int reverseEdge) {
		ensureEdgeCapacity(edgeCount + 1);
		if (firstOutbound[fromID] != -1)
			nextOutbound[edgeCount] = firstOutbound[fromID];
		else
			nextOutbound[edgeCount] = -1;
		firstOutbound[fromID] = edgeCount;
		if (firstInbound != null) {
			if (firstInbound[toID] != -1)
				nextInbound[edgeCount] = firstInbound[toID];
			else
				nextInbound[edgeCount] = -1;
			firstInbound[toID] = edgeCount;
		}
		this.from[edgeCount] = fromID;
		this.to[edgeCount] = toID;
		if (capacity != 0) {
			if (this.capacity == null)
				this.capacity = new long[from.length];
			this.capacity[edgeCount] = capacity;
		}
		if (weight != 0) {
			if (this.weight == null)
				this.weight = new long[from.length];
			this.weight[edgeCount] = weight;
		}
		if (reverseEdge != -1) {
			if (this.reverseEdge == null) {
				this.reverseEdge = new int[from.length];
				Arrays.fill(this.reverseEdge, 0, edgeCount, -1);
			}
			this.reverseEdge[edgeCount] = reverseEdge;
		}
		if (edges != null)
			edges[edgeCount] = createEdge(edgeCount);
		return edgeCount++;
	}

	protected final GraphEdge createEdge(int id) {
		return new GraphEdge(id);
	}

	public final int addFlowWeightedEdge(int from, int to, long weight,
			long capacity) {
		if (capacity == 0) {
			return addEdge(from, to, weight, 0, -1);
		} else {
			int lastEdgeCount = edgeCount;
			addEdge(to, from, -weight, 0, lastEdgeCount + entriesPerEdge());
			return addEdge(from, to, weight, capacity, lastEdgeCount);
		}
	}

	protected int entriesPerEdge() {
		return 1;
	}

	public final int addFlowEdge(int from, int to, long capacity) {
		return addFlowWeightedEdge(from, to, 0, capacity);
	}

	public final int addWeightedEdge(int from, int to, long weight) {
		return addFlowWeightedEdge(from, to, weight, 0);
	}

	public final int addSimpleEdge(int from, int to) {
		return addWeightedEdge(from, to, 0);
	}

	public final int vertexCount() {
		return vertexCount;
	}

	public final int edgeCount() {
		return edgeCount;
	}

	protected final int edgeCapacity() {
		return from.length;
	}

	public final Edge edge(int id) {
		initEdges();
		return edges[id];
	}

	public final int firstOutbound(int vertex) {
		int id = firstOutbound[vertex];
		while (id != -1 && isRemoved(id))
			id = nextOutbound[id];
		return id;
	}

	public final int nextOutbound(int id) {
		id = nextOutbound[id];
		while (id != -1 && isRemoved(id))
			id = nextOutbound[id];
		return id;
	}

	public final int firstInbound(int vertex) {
		initInbound();
		int id = firstInbound[vertex];
		while (id != -1 && isRemoved(id))
			id = nextInbound[id];
		return id;
	}

	public final int nextInbound(int id) {
		initInbound();
		id = nextInbound[id];
		while (id != -1 && isRemoved(id))
			id = nextInbound[id];
		return id;
	}

	public final int source(int id) {
		return from[id];
	}

	public final int destination(int id) {
		return to[id];
	}

	public final long weight(int id) {
		if (weight == null)
			return 0;
		return weight[id];
	}

	public final long capacity(int id) {
		if (capacity == null)
			return 0;
		return capacity[id];
	}

	public final long flow(int id) {
		if (reverseEdge == null)
			return 0;
		return capacity[reverseEdge[id]];
	}

	public final void pushFlow(int id, long flow) {
		if (flow == 0)
			return;
		if (flow > 0) {
			if (capacity(id) < flow)
				throw new IllegalArgumentException("Not enough capacity");
		} else {
			if (flow(id) < -flow)
				throw new IllegalArgumentException("Not enough capacity");
		}
		capacity[id] -= flow;
		capacity[reverseEdge[id]] += flow;
	}

	public int transposed(int id) {
		return -1;
	}

	public final int reverse(int id) {
		if (reverseEdge == null)
			return -1;
		return reverseEdge[id];
	}

	public final void addVertices(int count) {
		ensureVertexCapacity(vertexCount + count);
		Arrays.fill(firstOutbound, vertexCount, vertexCount + count, -1);
		if (firstInbound != null)
			Arrays.fill(firstInbound, vertexCount, vertexCount + count, -1);
		vertexCount += count;
	}

	protected final void initEdges() {
		if (edges == null) {
			edges = new Edge[from.length];
			for (int i = 0; i < edgeCount; i++)
				edges[i] = createEdge(i);
		}
	}

	public final void removeVertex(int vertex) {
		int id = firstOutbound[vertex];
		while (id != -1) {
			removeEdge(id);
			id = nextOutbound[id];
		}
		initInbound();
		id = firstInbound[vertex];
		while (id != -1) {
			removeEdge(id);
			id = nextInbound[id];
		}
	}

	private void initInbound() {
		if (firstInbound == null) {
			firstInbound = new int[firstOutbound.length];
			Arrays.fill(firstInbound, 0, vertexCount, -1);
			nextInbound = new int[from.length];
			for (int i = 0; i < edgeCount; i++) {
				nextInbound[i] = firstInbound[to[i]];
				firstInbound[to[i]] = i;
			}
		}
	}

	public final boolean flag(int id, int bit) {
		return (flags[id] >> bit & 1) != 0;
	}

	public final void setFlag(int id, int bit) {
		flags[id] |= 1 << bit;
	}

	public final void removeFlag(int id, int bit) {
		flags[id] &= -1 - (1 << bit);
	}

	public final void removeEdge(int id) {
		setFlag(id, REMOVED_BIT);
	}

	public final void restoreEdge(int id) {
		removeFlag(id, REMOVED_BIT);
	}

	public final boolean isRemoved(int id) {
		return flag(id, REMOVED_BIT);
	}

	public final Iterable<Edge> outbound(final int id) {
		initEdges();
		return new Iterable<Edge>() {
			public Iterator<Edge> iterator() {
				return new EdgeIterator(id, firstOutbound, nextOutbound);
			}
		};
	}

	public final Iterable<Edge> inbound(final int id) {
		initEdges();
		initInbound();
		return new Iterable<Edge>() {
			public Iterator<Edge> iterator() {
				return new EdgeIterator(id, firstInbound, nextInbound);
			}
		};
	}

	protected void ensureEdgeCapacity(int size) {
		if (from.length < size) {
			int newSize = Math.max(size, 2 * from.length);
			if (edges != null)
				edges = resize(edges, newSize);
			from = resize(from, newSize);
			to = resize(to, newSize);
			nextOutbound = resize(nextOutbound, newSize);
			if (nextInbound != null)
				nextInbound = resize(nextInbound, newSize);
			if (weight != null)
				weight = resize(weight, newSize);
			if (capacity != null)
				capacity = resize(capacity, newSize);
			if (reverseEdge != null)
				reverseEdge = resize(reverseEdge, newSize);
			flags = resize(flags, newSize);
		}
	}

	private void ensureVertexCapacity(int size) {
		if (firstOutbound.length < size) {
			int newSize = Math.max(size, 2 * from.length);
			firstOutbound = resize(firstOutbound, newSize);
			if (firstInbound != null)
				firstInbound = resize(firstInbound, newSize);
		}
	}

	protected final int[] resize(int[] array, int size) {
		int[] newArray = new int[size];
		System.arraycopy(array, 0, newArray, 0, array.length);
		return newArray;
	}

	private long[] resize(long[] array, int size) {
		long[] newArray = new long[size];
		System.arraycopy(array, 0, newArray, 0, array.length);
		return newArray;
	}

	private Edge[] resize(Edge[] array, int size) {
		Edge[] newArray = new Edge[size];
		System.arraycopy(array, 0, newArray, 0, array.length);
		return newArray;
	}

	public final boolean isSparse() {
		return vertexCount == 0 || edgeCount * 20 / vertexCount <= vertexCount;
	}

	protected class GraphEdge implements Edge {
		protected int id;

		protected GraphEdge(int id) {
			this.id = id;
		}

		public int getSource() {
			return source(id);
		}

		public int getDestination() {
			return destination(id);
		}

		public long getWeight() {
			return weight(id);
		}

		public long getCapacity() {
			return capacity(id);
		}

		public long getFlow() {
			return flow(id);
		}

		public void pushFlow(long flow) {
			Graph.this.pushFlow(id, flow);
		}

		public boolean getFlag(int bit) {
			return flag(id, bit);
		}

		public void setFlag(int bit) {
			Graph.this.setFlag(id, bit);
		}

		public void removeFlag(int bit) {
			Graph.this.removeFlag(id, bit);
		}

		public int getTransposedID() {
			return transposed(id);
		}

		public Edge getTransposedEdge() {
			int reverseID = getTransposedID();
			if (reverseID == -1)
				return null;
			initEdges();
			return edge(reverseID);
		}

		public int getReverseID() {
			return reverse(id);
		}

		public Edge getReverseEdge() {
			int reverseID = getReverseID();
			if (reverseID == -1)
				return null;
			initEdges();
			return edge(reverseID);
		}

		public int getID() {
			return id;
		}

		public void remove() {
			removeEdge(id);
		}

		public void restore() {
			restoreEdge(id);
		}
	}

	public class EdgeIterator implements Iterator<Edge> {
		private int edgeID;
		private final int[] next;
		private int lastID = -1;

		public EdgeIterator(int id, int[] first, int[] next) {
			this.next = next;
			edgeID = nextEdge(first[id]);
		}

		private int nextEdge(int id) {
			while (id != -1 && isRemoved(id))
				id = next[id];
			return id;
		}

		public boolean hasNext() {
			return edgeID != -1;
		}

		public Edge next() {
			if (edgeID == -1)
				throw new NoSuchElementException();
			lastID = edgeID;
			edgeID = nextEdge(next[lastID]);
			return edges[lastID];
		}

		public void remove() {
			if (lastID == -1)
				throw new IllegalStateException();
			removeEdge(lastID);
			lastID = -1;
		}
	}

}

class MiscUtils {
	public static final int[] DX4 = { 1, 0, -1, 0 };
	public static final int[] DY4 = { 0, -1, 0, 1 };
	public static final int[] DX8 = { 1, 1, 1, 0, -1, -1, -1, 0 };
	public static final int[] DY8 = { -1, 0, 1, 1, 1, 0, -1, -1 };
	public static final int[] DX_KNIGHT = { 2, 1, -1, -2, -2, -1, 1, 2 };
	public static final int[] DY_KNIGHT = { 1, 2, 2, 1, -1, -2, -2, -1 };

	private static final String[] ROMAN_TOKENS = { "M", "CM", "D", "CD", "C",
			"XC", "L", "XL", "X", "IX", "V", "IV", "I" };
	private static final int[] ROMAN_VALUES = { 1000, 900, 500, 400, 100, 90,
			50, 40, 10, 9, 5, 4, 1 };

	public static long josephProblem(long n, int k) {
		if (n == 1)
			return 0;
		if (k == 1)
			return n - 1;
		if (k > n)
			return (josephProblem(n - 1, k) + k) % n;
		long count = n / k;
		long result = josephProblem(n - count, k);
		result -= n % k;
		if (result < 0)
			result += n;
		else
			result += result / (k - 1);
		return result;
	}

	public static boolean isValidCell(int row, int column, int rowCount,
			int columnCount) {
		return row >= 0 && row < rowCount && column >= 0
				&& column < columnCount;
	}

	public static List<Integer> getPath(int[] last, int destination) {
		List<Integer> path = new ArrayList<Integer>();
		while (destination != -1) {
			path.add(destination);
			destination = last[destination];
		}
		inPlaceReverse(path);
		return path;
	}

	private static void inPlaceReverse(List<Integer> list) {
		for (int i = 0, j = list.size() - 1; i < j; i++, j--)
			swap(list, i, j);
	}

	private static void swap(List<Integer> list, int first, int second) {
		if (first == second)
			return;
		int temp = list.get(first);
		list.set(first, list.get(second));
		list.set(second, temp);
	}

	public static List<Integer> getPath(int[][] lastIndex,
			int[][] lastPathNumber, int destination, int pathNumber) {
		List<Integer> path = new ArrayList<Integer>();
		while (destination != -1 || pathNumber != 0) {
			path.add(destination);
			int nextDestination = lastIndex[destination][pathNumber];
			pathNumber = lastPathNumber[destination][pathNumber];
			destination = nextDestination;
		}
		inPlaceReverse(path);
		return path;
	}

	public static long maximalRectangleSum(long[][] array) {
		int n = array.length;
		int m = array[0].length;
		long[][] partialSums = new long[n + 1][m + 1];
		for (int i = 0; i < n; i++) {
			long rowSum = 0;
			for (int j = 0; j < m; j++) {
				rowSum += array[i][j];
				partialSums[i + 1][j + 1] = partialSums[i][j + 1] + rowSum;
			}
		}
		long result = Long.MIN_VALUE;
		for (int i = 0; i < m; i++) {
			for (int j = i; j < m; j++) {
				long minPartialSum = 0;
				for (int k = 1; k <= n; k++) {
					long current = partialSums[k][j + 1] - partialSums[k][i];
					result = Math.max(result, current - minPartialSum);
					minPartialSum = Math.min(minPartialSum, current);
				}
			}
		}
		return result;
	}

	public static int parseIP(String ip) {
		String[] components = ip.split("[.]");
		int result = 0;
		for (int i = 0; i < 4; i++)
			result += (1 << (24 - 8 * i)) * Integer.parseInt(components[i]);
		return result;
	}

	public static String buildIP(int mask) {
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < 4; i++) {
			if (i != 0)
				result.append('.');
			result.append(mask >> (24 - 8 * i) & 255);
		}
		return result.toString();
	}

	public static long binarySearch(long from, long to,
			Function<Long, Boolean> function) {
		while (from < to) {
			long argument = from + (to - from) / 2;
			if (function.value(argument))
				to = argument;
			else
				from = argument + 1;
		}
		return from;
	}

	public static <T> boolean equals(T first, T second) {
		return first == null && second == null || first != null
				&& first.equals(second);
	}

	public static boolean isVowel(char ch) {
		ch = Character.toUpperCase(ch);
		return ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'
				|| ch == 'Y';
	}

	public static boolean isStrictVowel(char ch) {
		ch = Character.toUpperCase(ch);
		return ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U';
	}

	public static String convertToRoman(int number) {
		StringBuilder result = new StringBuilder();
		for (int i = 0; i < ROMAN_TOKENS.length; i++) {
			while (number >= ROMAN_VALUES[i]) {
				number -= ROMAN_VALUES[i];
				result.append(ROMAN_TOKENS[i]);
			}
		}
		return result.toString();
	}

	public static int convertFromRoman(String number) {
		int result = 0;
		for (int i = 0; i < ROMAN_TOKENS.length; i++) {
			while (number.startsWith(ROMAN_TOKENS[i])) {
				number = number.substring(ROMAN_TOKENS[i].length());
				result += ROMAN_VALUES[i];
			}
		}
		return result;
	}

	public static int distance(int x1, int y1, int x2, int y2) {
		int dx = x1 - x2;
		int dy = y1 - y2;
		return dx * dx + dy * dy;
	}

	public static <T extends Comparable<T>> T min(T first, T second) {
		if (first.compareTo(second) <= 0)
			return first;
		return second;
	}

	public static <T extends Comparable<T>> T max(T first, T second) {
		if (first.compareTo(second) <= 0)
			return second;
		return first;
	}

	public static void decreaseByOne(int[]... arrays) {
		for (int[] array : arrays) {
			for (int i = 0; i < array.length; i++)
				array[i]--;
		}
	}

	public static int[] getIntArray(String s) {
		String[] tokens = s.split(" ");
		int[] result = new int[tokens.length];
		for (int i = 0; i < result.length; i++)
			result[i] = Integer.parseInt(tokens[i]);
		return result;
	}
}

class IntegerUtils {
	public static long gcd(long a, long b) {
		a = Math.abs(a);
		b = Math.abs(b);
		while (b != 0) {
			long temp = a % b;
			a = b;
			b = temp;
		}
		return a;
	}

	public static int gcd(int a, int b) {
		a = Math.abs(a);
		b = Math.abs(b);
		while (b != 0) {
			int temp = a % b;
			a = b;
			b = temp;
		}
		return a;
	}

	public static int[] generatePrimes(int upTo) {
		int[] isPrime = generateBitPrimalityTable(upTo);
		List<Integer> primes = new ArrayList<Integer>();
		for (int i = 0; i < upTo; i++) {
			if ((isPrime[i >> 5] >>> (i & 31) & 1) == 1)
				primes.add(i);
		}
		int[] array = new int[primes.size()];
		for (int i = 0; i < array.length; i++)
			array[i] = primes.get(i);
		return array;
	}

	public static boolean[] generatePrimalityTable(int upTo) {
		boolean[] isPrime = new boolean[upTo];
		if (upTo < 2)
			return isPrime;
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for (int i = 2; i * i < upTo; i++) {
			if (isPrime[i]) {
				for (int j = i * i; j < upTo; j += i)
					isPrime[j] = false;
			}
		}
		return isPrime;
	}

	public static int[] generateBitPrimalityTable(int upTo) {
		int[] isPrime = new int[(upTo + 31) >> 5];
		if (upTo < 2)
			return isPrime;
		Arrays.fill(isPrime, -1);
		isPrime[0] &= -4;
		for (int i = 2; i * i < upTo; i++) {
			if ((isPrime[i >> 5] >>> (i & 31) & 1) == 1) {
				for (int j = i * i; j < upTo; j += i)
					isPrime[j >> 5] &= -1 - (1 << (j & 31));
			}
		}
		return isPrime;
	}

	public static int[] generateDivisorTable(int upTo) {
		int[] divisor = new int[upTo];
		for (int i = 1; i < upTo; i++)
			divisor[i] = i;
		for (int i = 2; i * i < upTo; i++) {
			if (divisor[i] == i) {
				for (int j = i * i; j < upTo; j += i)
					divisor[j] = i;
			}
		}
		return divisor;
	}

	public static long powerInFactorial(long n, long p) {
		long result = 0;
		while (n != 0) {
			result += n /= p;
		}
		return result;
	}

	public static int sumDigits(CharSequence number) {
		int result = 0;
		for (int i = number.length() - 1; i >= 0; i--)
			result += digitValue(number.charAt(i));
		return result;
	}

	public static int digitValue(char digit) {
		if (Character.isDigit(digit))
			return digit - '0';
		if (Character.isUpperCase(digit))
			return digit + 10 - 'A';
		return digit + 10 - 'a';
	}

	public static int longCompare(long a, long b) {
		if (a < b)
			return -1;
		if (a > b)
			return 1;
		return 0;
	}

	public static long[][] generateBinomialCoefficients(int n) {
		long[][] result = new long[n + 1][n + 1];
		for (int i = 0; i <= n; i++) {
			result[i][0] = 1;
			for (int j = 1; j <= i; j++)
				result[i][j] = result[i - 1][j - 1] + result[i - 1][j];
		}
		return result;
	}

	public static long[][] generateBinomialCoefficients(int n, long module) {
		long[][] result = new long[n + 1][n + 1];
		if (module == 1)
			return result;
		for (int i = 0; i <= n; i++) {
			result[i][0] = 1;
			for (int j = 1; j <= i; j++) {
				result[i][j] = result[i - 1][j - 1] + result[i - 1][j];
				if (result[i][j] >= module)
					result[i][j] -= module;
			}
		}
		return result;
	}

	public static long[] generateBinomialRow(int n, long module) {
		long[] result = generateReverse(n + 1, module);
		result[0] = 1;
		for (int i = 1; i <= n; i++)
			result[i] = result[i - 1] * (n - i + 1) % module * result[i]
					% module;
		return result;
	}

	public static int[] representationInBase(long number, int base) {
		long basePower = base;
		int exponent = 1;
		while (number >= basePower) {
			basePower *= base;
			exponent++;
		}
		int[] representation = new int[exponent];
		for (int i = 0; i < exponent; i++) {
			basePower /= base;
			representation[i] = (int) (number / basePower);
			number %= basePower;
		}
		return representation;
	}

	public static int trueDivide(int a, int b) {
		return (a - trueMod(a, b)) / b;
	}

	public static long trueDivide(long a, long b) {
		return (a - trueMod(a, b)) / b;
	}

	public static int trueMod(int a, int b) {
		a %= b;
		a += b;
		a %= b;
		return a;
	}

	public static long trueMod(long a, long b) {
		a %= b;
		a += b;
		a %= b;
		return a;
	}

	public static long factorial(int n) {
		long result = 1;
		for (int i = 2; i <= n; i++)
			result *= i;
		return result;
	}

	public static long factorial(int n, long mod) {
		long result = 1;
		for (int i = 2; i <= n; i++)
			result = result * i % mod;
		return result % mod;
	}

	public static List<Pair<Long, Integer>> factorize(long number) {
		List<Pair<Long, Integer>> result = new ArrayList<Pair<Long, Integer>>();
		for (long i = 2; i * i <= number; i++) {
			if (number % i == 0) {
				int power = 0;
				do {
					power++;
					number /= i;
				} while (number % i == 0);
				result.add(Pair.makePair(i, power));
			}
		}
		if (number != 1)
			result.add(Pair.makePair(number, 1));
		return result;
	}

	public static List<Long> getDivisors(long number) {
		List<Pair<Long, Integer>> primeDivisors = factorize(number);
		return getDivisorsImpl(primeDivisors, 0, 1, new ArrayList<Long>());
	}

	private static List<Long> getDivisorsImpl(
			List<Pair<Long, Integer>> primeDivisors, int index, long current,
			List<Long> result) {
		if (index == primeDivisors.size()) {
			result.add(current);
			return result;
		}
		long p = primeDivisors.get(index).first;
		int power = primeDivisors.get(index).second;
		for (int i = 0; i <= power; i++) {
			getDivisorsImpl(primeDivisors, index + 1, current, result);
			current *= p;
		}
		return result;
	}

	public static long power(long base, long exponent) {
		if (exponent == 0)
			return 1;
		long result = power(base, exponent >> 1);
		result = result * result;
		if ((exponent & 1) != 0)
			result = result * base;
		return result;
	}

	public static long power(long base, long exponent, long mod) {
		if (base >= mod)
			base %= mod;
		if (exponent == 0)
			return 1 % mod;
		long result = power(base, exponent >> 1, mod);
		result = result * result % mod;
		if ((exponent & 1) != 0)
			result = result * base % mod;
		return result;
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	public static long[] generateFibonacci(long upTo) {
		int count = 0;
		long last = 0;
		long current = 1;
		while (current <= upTo) {
			long next = last + current;
			last = current;
			current = next;
			count++;
		}
		return generateFibonacci(count, -1);
	}

	public static long[] generateFibonacci(int count, long module) {
		long[] result = new long[count];
		if (module == -1) {
			if (count != 0)
				result[0] = 1;
			if (count > 1)
				result[1] = 1;
			for (int i = 2; i < count; i++)
				result[i] = result[i - 1] + result[i - 2];
		} else {
			if (count != 0)
				result[0] = 1 % module;
			if (count > 1)
				result[1] = 1 % module;
			for (int i = 2; i < count; i++)
				result[i] = (result[i - 1] + result[i - 2]) % module;
		}
		return result;
	}

	public static long[] generateHappy(int digits) {
		long[] happy = new long[(1 << (digits + 1)) - 2];
		happy[0] = 4;
		happy[1] = 7;
		int first = 0;
		int last = 2;
		for (int i = 2; i <= digits; i++) {
			for (int j = 0; j < last - first; j++) {
				happy[last + 2 * j] = 10 * happy[first + j] + 4;
				happy[last + 2 * j + 1] = 10 * happy[first + j] + 7;
			}
			int next = last + 2 * (last - first);
			first = last;
			last = next;
		}
		return happy;
	}

	public static long[] generateFactorial(int count, long module) {
		long[] result = new long[count];
		if (module == -1) {
			if (count != 0)
				result[0] = 1;
			for (int i = 1; i < count; i++)
				result[i] = result[i - 1] * i;
		} else {
			if (count != 0)
				result[0] = 1 % module;
			for (int i = 1; i < count; i++)
				result[i] = (result[i - 1] * i) % module;
		}
		return result;
	}

	public static long reverse(long number, long module) {
		return power(number, module - 2, module);
	}

	public static boolean isPrime(long number) {
		if (number < 2)
			return false;
		for (long i = 2; i * i <= number; i++) {
			if (number % i == 0)
				return false;
		}
		return true;
	}

	public static long[] generateReverse(int upTo, long module) {
		long[] result = new long[upTo];
		if (upTo > 1)
			result[1] = 1;
		for (int i = 2; i < upTo; i++)
			result[i] = (module - module / i * result[((int) (module % i))]
					% module)
					% module;
		return result;
	}

	public static long[] generateReverseFactorials(int upTo, long module) {
		long[] result = generateReverse(upTo, module);
		if (upTo > 0)
			result[0] = 1;
		for (int i = 1; i < upTo; i++)
			result[i] = result[i] * result[i - 1] % module;
		return result;
	}

	public static long[] generatePowers(long base, int count, long mod) {
		long[] result = new long[count];
		if (count != 0)
			result[0] = 1 % mod;
		for (int i = 1; i < count; i++)
			result[i] = result[i - 1] * base % mod;
		return result;
	}

	public static long nextPrime(long from) {
		if (from <= 2)
			return 2;
		from += 1 - (from & 1);
		while (!isPrime(from))
			from += 2;
		return from;
	}

	public static long binomialCoefficient(int n, int m, long mod) {
		if (m < 0 || m > n)
			return 0;
		if (2 * m > n)
			m = n - m;
		long result = 1;
		for (int i = n - m + 1; i <= n; i++)
			result = result * i % mod;
		return result
				* BigInteger.valueOf(factorial(m, mod))
						.modInverse(BigInteger.valueOf(mod)).longValue() % mod;
	}

	public static boolean isSquare(long number) {
		long sqrt = Math.round(Math.sqrt(number));
		return sqrt * sqrt == number;
	}

	public static long findCommon(long aRemainder, long aMod, long bRemainder,
			long bMod) {
		long modGCD = gcd(aMod, bMod);
		long gcdRemainder = aRemainder % modGCD;
		if (gcdRemainder != bRemainder % modGCD)
			return -1;
		aMod /= modGCD;
		aRemainder /= modGCD;
		bMod /= modGCD;
		bRemainder /= modGCD;
		long aReverse = BigInteger.valueOf(aMod)
				.modInverse(BigInteger.valueOf(bMod)).longValue();
		long bReverse = BigInteger.valueOf(bMod)
				.modInverse(BigInteger.valueOf(aMod)).longValue();
		long mod = aMod * bMod;
		return (bReverse * aRemainder % mod * bMod + aReverse * bRemainder
				% mod * aMod)
				% mod * modGCD + gcdRemainder;
	}

	public static long[] generatePowers(long base, long maxValue) {
		if (maxValue <= 0)
			return new long[0];
		int size = 1;
		long current = 1;
		while (maxValue / base >= current) {
			current *= base;
			size++;
		}
		return generatePowers(base, size, Long.MAX_VALUE);
	}
}

interface IntComparator extends Comparator<Integer> {
	public static final IntComparator DEFAULT = new IntComparator() {
		public int compare(Integer first, Integer second) {
			if (first < second)
				return -1;
			if (first > second)
				return 1;
			return 0;
		}
	};

	public static final IntComparator REVERSE = new IntComparator() {
		public int compare(Integer first, Integer second) {
			if (first < second)
				return 1;
			if (first > second)
				return -1;
			return 0;
		}
	};

	public int compare(Integer first, Integer second);
}

class BidirectionalGraph extends Graph {
	public int[] transposedEdge;

	public BidirectionalGraph(int vertexCount) {
		this(vertexCount, vertexCount);
	}

	public BidirectionalGraph(int vertexCount, int edgeCapacity) {
		super(vertexCount, 2 * edgeCapacity);
		transposedEdge = new int[2 * edgeCapacity];
	}

	public static BidirectionalGraph createGraph(int vertexCount, int[] from,
			int[] to) {
		BidirectionalGraph graph = new BidirectionalGraph(vertexCount,
				from.length);
		for (int i = 0; i < from.length; i++)
			graph.addSimpleEdge(from[i], to[i]);
		return graph;
	}

	public static BidirectionalGraph createWeightedGraph(int vertexCount,
			int[] from, int[] to, long[] weight) {
		BidirectionalGraph graph = new BidirectionalGraph(vertexCount,
				from.length);
		for (int i = 0; i < from.length; i++)
			graph.addWeightedEdge(from[i], to[i], weight[i]);
		return graph;
	}

	public static BidirectionalGraph createFlowGraph(int vertexCount,
			int[] from, int[] to, long[] capacity) {
		BidirectionalGraph graph = new BidirectionalGraph(vertexCount,
				from.length * 2);
		for (int i = 0; i < from.length; i++)
			graph.addFlowEdge(from[i], to[i], capacity[i]);
		return graph;
	}

	public static BidirectionalGraph createFlowWeightedGraph(int vertexCount,
			int[] from, int[] to, long[] weight, long[] capacity) {
		BidirectionalGraph graph = new BidirectionalGraph(vertexCount,
				from.length * 2);
		for (int i = 0; i < from.length; i++)
			graph.addFlowWeightedEdge(from[i], to[i], weight[i], capacity[i]);
		return graph;
	}

	@Override
	public int addEdge(int fromID, int toID, long weight, long capacity,
			int reverseEdge) {
		int lastEdgeCount = edgeCount;
		super.addEdge(fromID, toID, weight, capacity, reverseEdge);
		super.addEdge(toID, fromID, weight, capacity, reverseEdge == -1 ? -1
				: reverseEdge + 1);
		this.transposedEdge[lastEdgeCount] = lastEdgeCount + 1;
		this.transposedEdge[lastEdgeCount + 1] = lastEdgeCount;
		return lastEdgeCount;
	}

	@Override
	protected int entriesPerEdge() {
		return 2;
	}

	@Override
	public final int transposed(int id) {
		return transposedEdge[id];
	}

	@Override
	protected void ensureEdgeCapacity(int size) {
		if (size > edgeCapacity()) {
			super.ensureEdgeCapacity(size);
			transposedEdge = resize(transposedEdge, edgeCapacity());
		}
	}
}

class Pair<U, V> implements Comparable<Pair<U, V>> {
	public final U first;
	public final V second;

	public static <U, V> Pair<U, V> makePair(U first, V second) {
		return new Pair<U, V>(first, second);
	}

	private Pair(U first, V second) {
		this.first = first;
		this.second = second;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Pair pair = (Pair) o;

		return !(first != null ? !first.equals(pair.first) : pair.first != null)
				&& !(second != null ? !second.equals(pair.second)
						: pair.second != null);

	}

	@Override
	public int hashCode() {
		int result = first != null ? first.hashCode() : 0;
		result = 31 * result + (second != null ? second.hashCode() : 0);
		return result;
	}

	public Pair<V, U> swap() {
		return makePair(second, first);
	}

	@Override
	public String toString() {
		return "(" + first + "," + second + ")";
	}

	@SuppressWarnings({ "unchecked" })
	public int compareTo(Pair<U, V> o) {
		int value = ((Comparable<U>) first).compareTo(o.first);
		if (value != 0)
			return value;
		return ((Comparable<V>) second).compareTo(o.second);
	}
}

interface Edge {
	public int getSource();

	public int getDestination();

	public long getWeight();

	public long getCapacity();

	public long getFlow();

	public void pushFlow(long flow);

	public boolean getFlag(int bit);

	public void setFlag(int bit);

	public void removeFlag(int bit);

	public int getTransposedID();

	public Edge getTransposedEdge();

	public int getReverseID();

	public Edge getReverseEdge();

	public int getID();

	public void remove();

	public void restore();
}

interface Function<A, V> {
	public abstract V value(A argument);
}

import java.math.BigInteger;
import java.util.Scanner;

public class B371 {
	private static int count = 0;

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int gcdVal = gcd(a, b);

		if(a==b)
			System.out.println(count);

		if(divide(a, gcdVal) && divide(b, gcdVal))
			System.out.println(count);
		else
			System.out.println("-1");

		in.close();
	}

	public static int gcd(int a, int b) {
	    BigInteger b1 = BigInteger.valueOf(a);
	    BigInteger b2 = BigInteger.valueOf(b);
	    BigInteger gcd = b1.gcd(b2);
	    return gcd.intValue();
	}

	public static boolean divide(int a, int gcd)
	{
		if(a%2 == 0)
		{
			count ++;
			if(a/2 == gcd)
				return true;
			else
				return divide(a/2, gcd);
		}
		else if(a%3 == 0)
		{
			count++;
			if(a/3 == gcd)
				return true;
			else
				return divide(a/3, gcd);
		}
		else if(a%5 == 0)
		{
			count++;
			if(a/5 == gcd)
				return true;
			else
				return divide(a/5, gcd);
		}
		return false;
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author el-Bishoy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        Div2B_371_FoxDividingCheeze solver = new Div2B_371_FoxDividingCheeze();
        solver.solve(1, in, out);
        out.close();
    }

    static class Div2B_371_FoxDividingCheeze {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int a = in.nextInt(), b = in.nextInt();

            if (a == b) {
                out.println(0);
                return;
            }

            boolean possible = true;
            int cnt = 0;
            while (a != b) {

                if (isPrime(a) && isPrime(b)) {
                    possible = false;
                    break;
                }

                int max = Math.max(a, b);
                int min = Math.min(a, b);

                if (max % 2 == 0) {
                    int fox = max / 2;
                    max = max - fox;
                    cnt++;
                } else if (max % 3 == 0) {
                    int fox = (2 * max) / 3;
                    max = max - fox;
                    cnt++;
                } else if ((max % 5 == 0)) {
                    int fox = (4 * max) / 5;
                    max = max - fox;
                    cnt++;
                }

                if (max == min)
                    break;

                if (min % 2 == 0) {
                    int fox = min / 2;
                    min = min - fox;
                    cnt++;
                } else if (min % 3 == 0) {
                    int fox = (2 * min) / 3;
                    min = min - fox;
                    cnt++;
                } else if ((min % 5 == 0)) {
                    int fox = (4 * min) / 5;
                    min = min - fox;
                    cnt++;
                }

                a = max;
                b = min;
            }

            if (possible)
                out.println(cnt);
            else
                out.println(-1);

        }

        static boolean isPrime(long n) {

            if (n <= 1) return false;
            if (n == 2) return true;
            if (n % 2 == 0) return false;

            for (int i = 3; i * i <= n; i++) {
                if (n % i == 0)
                    return false;

            }

            return true;

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import static java.lang.Math.abs;

public class FoxDividingCheese implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(System.out);

    public void solve() {
        int a = in.ni(), b = in.ni();
        Map<Integer, Integer> x = factorize(a), y = factorize(b);
        int result = 0;
        for (int k : new int[]{2, 3, 4}) {
            result += abs(x.getOrDefault(k, 0) - y.getOrDefault(k, 0));
            x.remove(k);
            y.remove(k);
        }
        for (Map.Entry<Integer, Integer> entry : x.entrySet()) {
            if (!entry.getValue().equals(y.getOrDefault(entry.getKey(), 0))) {
                result = -1;
                break;
            }
        }
        out.println(result);
    }

    private Map<Integer, Integer> factorize(int n) {
        Map<Integer, Integer> result = new HashMap<>();
        for (int i = 2; i * i <= n; i++) {
            while (n % i == 0) {
                int cnt = result.getOrDefault(i, 0) + 1;
                result.put(i, cnt);
                n /= i;
            }
        }
        if (n > 1) {
            int cnt = result.getOrDefault(n, 0) + 1;
            result.put(n, cnt);
        }
        return result;
    }

    @Override
    public void close() throws IOException {
        in.close();
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public void close() throws IOException {
            reader.close();
        }
    }

    public static void main(String[] args) throws IOException {
        try (FoxDividingCheese instance = new FoxDividingCheese()) {
            instance.solve();
        }
    }
}

import java.util.*;
import java.io.*;
import java.math.*;
public class Euler {

	public static int gcd(int a, int b) {
		if (b == 0) return a;
		else return gcd(b, a % b);
	}

	public static void main(String[] args){

		FastReader in = new FastReader();
		PrintWriter o = new PrintWriter(System.out);

		int a = in.nextInt();
		int b = in.nextInt();

		int g = gcd(a, b);
		int x = a / g;
		int y = b / g;

		if (x % 7 == 0 || y % 7 == 0) {

			o.println("-1");
			o.flush();
			o.close();
			return;

		}

		int two = x % 2 == 0 ? (int)Math.sqrt(x) : 0;
		int three = x % 3 == 0 ? (int)Math.sqrt(x) : 0;
		int five = x % 5 == 0 ? (int)Math.sqrt(x) : 0;

		int t = y % 2 == 0 ? (int)Math.sqrt(y) : 0;
		int th = y % 3 == 0 ? (int)Math.sqrt(y) : 0;
		int f = y % 5 == 0 ? (int)Math.sqrt(y) : 0;

		int ans = two + three + five + t + th + f;
		o.println(ans);

		o.flush();
		o.close();
		return;

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}

import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		Map<Integer, Integer> amap = new TreeMap<>();
                Map<Integer, Integer> bmap = new TreeMap<>();

                int a = nextInt();
                int b = nextInt();

                int x = Math.max(a, b);
                int bits = 0;
                for(int i = 2; i * i <= x; i++){
                        if(a > b){
                                while(a % i == 0){
                                        a = a/i;
                                        bits++;
                                        if(a == b) break;
                                }
                        }else if(b > a){
                               while(b % i == 0){
                                       b = b / i;
                                       bits++;
                                       if(b == a) break;
                               }
                        }
                        else if(a == b){
                                break;
                        }

                }

                if(a == b)System.out.println(bits);
                else {System.out.println(-1); //System.out.println(a + " " + b);
                }

	}

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class B {

	public static void main(String[] args) {
		B main = new B();
		main.run();
		System.exit(0);
	}

	private void run() {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(
					System.in));
			String[] str = in.readLine().split("\\s");
			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);
			if (!check(a) || !check(b)) {
				System.out.println(-1);
			} else {
				int d = gcd(a, b);
				int count = 0;
				a /= d;
				b /= d;
				while (a % 2 == 0) {
					a /= 2;
					count++;
				}
				while (a % 3 == 0) {
					a /= 3;
					count++;
				}
				while (a % 5 == 0) {
					a /= 5;
					count++;
				}
				while (b % 2 == 0) {
					b /= 2;
					count++;
				}
				while (b % 3 == 0) {
					b /= 3;
					count++;
				}
				while (b % 5 == 0) {
					b /= 5;
					count++;
				}
				System.out.println(count);
			}
		} catch (Exception e) {
		}
	}

	private int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	private boolean check(int a) {
		while (a % 2 == 0)
			a /= 2;
		while (a % 3 == 0)
			a /= 3;
		while (a % 5 == 0)
			a /= 5;
		return a == 1;
	}
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class D218_B {

	public static void main(String[] args) throws IOException {
		solve("input.txt","output.txt");
	}
	static boolean ok = false;

	public static long f(int a, int b, long res) {
		long ans = Long.MAX_VALUE-30000;
		long r = Long.MAX_VALUE-30000;
		if (a == b) {
			ok = true;
			return res;
		}

		int big = Math.max(a, b);
		int sm = Math.min(a, b);
		if (big%2 == 0) r = f(big/2,sm,++res);
		ans = Math.min(r, ans);
		if (big%3 == 0) r = f(2*(big/3),sm,++res);
		ans = Math.min(r, ans);
		if (big%5 == 0) r = f(4*(big/5),sm,++res);
		ans = Math.min(r, ans);

		return ans;
	}

	static void solve(String _in, String _out) throws IOException {
		BufferedReader in;
		PrintWriter out;
		try {
			in = new BufferedReader(new FileReader(_in));
			out = new PrintWriter(new File(_out));
		} catch (Exception e) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
		}
		StringTokenizer tok = new StringTokenizer(in.readLine());
		int a = Integer.valueOf(tok.nextToken());
		int b = Integer.valueOf(tok.nextToken());
		if (a == b) {
			out.println(0);
			out.close();
			return;
		}
		long ans = f(a,b,0);
		if (ok) out.println(ans); else out.println(-1);
		out.close();

	}

}

import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
	public static long mod= (long) (1e9 +7);
	public static void main(String args[])
	{
		//InputReader s= new InputReader(System.in);
		Scanner s= new Scanner(System.in);
		OutputStream outputStream= System.out;
		PrintWriter out= new PrintWriter(outputStream);
		int a= s.nextInt();
		int b= s.nextInt();
		if(a==b){
			out.println("0");
		}
		else{
		ArrayList<Integer> arr= new ArrayList<>();
		ArrayList<Integer> brr= new ArrayList<>();
		for(int i=2;i<=a;i++){
			while(a%i==0){
				arr.add(i);
				a/=i;
			}
		}
		for(int i=2;i<=b;i++){
			while(b%i==0){
				brr.add(i);
				b/=i;
			}
		}
		int counta2=0,counta3=0,counta5=0,countb2=0,countb3=0,countb5=0;
		for(int i=0;i<arr.size();i++){
			if(arr.get(i)==2) counta2++;
			if(arr.get(i)==3) counta3++;
			if(arr.get(i)==5) counta5++;
		}
		for(int i=0;i<brr.size();i++){
			if(brr.get(i)==2) countb2++;
			if(brr.get(i)==3) countb3++;
			if(brr.get(i)==5) countb5++;
		}
		if((counta2+counta3+counta5)!=arr.size() || (countb2+countb3+countb5)!=brr.size()){
			out.println("-1");
		}
		else{
			out.println(Math.abs(counta2-countb2) + Math.abs(counta3-countb3) + Math.abs(counta5-countb5));
		}
		}
		out.close();
	}
	static class InputReader {

	    public BufferedReader reader;
	    public StringTokenizer tokenizer;

	    public InputReader(InputStream inputstream) {
	      reader = new BufferedReader(new InputStreamReader(inputstream));
	      tokenizer = null;
	    }

	    public String nextLine(){
	    	String fullLine=null;
	    	while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	              fullLine=reader.readLine();
	            } catch (IOException e) {
	              throw new RuntimeException(e);
	            }
	            return fullLine;
	          }
	          return fullLine;
	    }
		public String next() {
	      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	        try {
	          tokenizer = new StringTokenizer(reader.readLine());
	        } catch (IOException e) {
	          throw new RuntimeException(e);
	        }
	      }
	      return tokenizer.nextToken();
	    }
		public long nextLong() {
		      return Long.parseLong(next());
		    }
	    public int nextInt() {
	      return Integer.parseInt(next());
	    }
	  }
	static class Pair implements Comparable<Pair>
	{
		long f,s;
		Pair(long ii, long cc)
		{
			f=ii;
			s=cc;
		}

		public int compareTo(Pair o)
		{
			return Long.compare(this.f, o.f);
		}

	}
	public static int gcd(int number1, int number2) {
		if(number2 == 0){
			return number1;
		}
		return gcd(number2, number1%number2);
	}
	public static int combinations(int n,int r){
		if(n==r) return 1;
		if(r==1) return n;
		if(r==0) return 1;
		return combinations(n-1,r)+ combinations(n-1,r-1);
	}
	public static long binomialCoeff(int n, int k)
	{
	    long C[][]= new long[n+1][k+1];
	    int i, j;

	    // Caculate value of Binomial Coefficient in bottom up manner
	    for (i = 0; i <= n; i++)
	    {
	        for (j = 0; j <= Math.min(i, k); j++)
	        {
	            // Base Cases
	            if (j == 0 || j == i)
	                C[i][j] = 1;

	            // Calculate value using previosly stored values
	            else
	                C[i][j] = C[i-1][j-1] + C[i-1][j];
	        }
	    }

	    return C[n][k];
	}

	public static int[] sieve(int N){
		int arr[]= new int[N+1];
		for(int i=2;i<Math.sqrt(N);i++){
			if(arr[i]==0){
				for(int j= i*i;j<= N;j= j+i){
					arr[j]=1;
				}
			}
		}
		return arr;
		// All the i for which arr[i]==0 are prime numbers.
	}
}