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

public class differ_sm_int {
	class Frac implements Comparable<Frac> {
		int a, b;

		public Frac(int a, int b) {
			super();
			if (b == 0)
				throw new AssertionError();
			if (b < 0) {
				a = -a;
				b = -b;
			}
			this.a = a;
			this.b = b;
		}

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

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

	void solve() throws IOException {
		int a = in.nextInt();
		int b = in.nextInt();
		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));
		}
		int ans = 0;
		if (a != 0 || b > 0) {
			if (Math.pow(Math.abs(a), Math.abs(b)) < Double.MAX_VALUE) {
				if (b >= 0) {
					ts.add(new Frac(pow(a, b), 1));
				} else {
					ts.add(new Frac(1, pow(a, -b)));
				}
			} else {
				ans++;
			}
		}
		if (b != 0 || a > 0) {
			if (Math.pow(Math.abs(b), Math.abs(a)) < Double.MAX_VALUE) {
				if (a >= 0) {
					ts.add(new Frac(pow(b, a), 1));
				} else {
					ts.add(new Frac(1, pow(b, -a)));
				}
			} else if (a != b) {
				ans++;
			}
		}
		out.println(ts.size() + ans);
	}

	private int pow(int x, int pow) {
		int res = 1;
		int a = x;
		while (pow > 0) {
			if (pow % 2 == 1) {
				res *= a;
			}
			a = a * a;
			pow /= 2;
		}
		return res;
	}

	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_int().run();
	}
}
