import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.TreeSet;

public class differ_sm_wrong1 {
	class Frac implements Comparable<Frac> {
		BigInteger a, b;

		public Frac(BigInteger a, BigInteger b) {
			super();
			if (b.signum() < 0) {
				a = a.negate();
				b = b.negate();
			}
			this.a = a;
			this.b = b;
		}

		public Frac(long a, long b) {
			this(BigInteger.valueOf(a), BigInteger.valueOf(b));
		}

		public Frac(long a) {
			this(a, 1);
		}

		@Override
		public int compareTo(Frac f) {
			return a.multiply(f.b).compareTo(f.a.multiply(b));
		}

		@Override
		public String toString() {
			return a + "/" + b;
		}
	}

	void solve() throws IOException {
		long a = in.nextInt();
		assert Math.abs(a) <= 1e9;
		long b = in.nextInt();
		assert Math.abs(b) <= 1e9;
		TreeSet<Frac> ts = new TreeSet<Frac>();
		ts.add(new Frac(a + b));
		ts.add(new Frac(a - b));
		ts.add(new Frac(b - a));
		ts.add(new Frac(a * b));
		if (b != 0) {
			ts.add(new Frac(a, b));
		}
		if (a != 0) {
			ts.add(new Frac(b, a));
		}
		for (Frac f1 : ts) {
			for (Frac f2 : ts) {
				if (f1 != f2 && f1.compareTo(f2) == 0) {
					throw new AssertionError(f1 + " " + f2 + " " + f1.compareTo(f2));
				}
			}
		}
		int ans = 0;

		if (a != 0 || b != 0) {
			if (canCalculatePow(a, b)) {
				if (b >= 0) {
					ts.add(new Frac(BigInteger.valueOf(a).pow((int) b), BigInteger.ONE));
				} else {
					ts.add(new Frac(BigInteger.ONE, BigInteger.valueOf(a).pow((int) -b)));
				}
			} else {
				ans++;
			}
			if (canCalculatePow(b, a)) {
				if (a >= 0) {
					ts.add(new Frac(BigInteger.valueOf(b).pow((int) a), BigInteger.ONE));
				} else {
					ts.add(new Frac(BigInteger.ONE, BigInteger.valueOf(b).pow((int) -a)));
				}
			} else if (a != b) {
				ans++;
			}
		}
		out.println(ts.size() + ans);
	}

	boolean canCalculatePow(long a, long b) {
		if (a == 0 && b <= 0)
			return false;
		a = Math.abs(a);
		b = Math.abs(b);
		return a == 1 || a == 0 || b < 10000;
	}

	Scanner in;
	PrintWriter out;
	final String filename = "differ";

	public void run() throws IOException {
		in = new Scanner(new FileReader(filename + ".in"));
		out = new PrintWriter(filename + ".out");
		solve();
		out.close();
	}

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