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

public class differ_ak {

	long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
	
	class Fraction {
		long p, q;

		public Fraction(long p, long q) {
			this.p = p;
			this.q = q;
			long g = gcd(Math.abs(p), Math.abs(q));
			if (g == 0)
				return;
			this.p /= g;
			this.q /= g;
			if (this.q < 0) {
				this.p *= -1;
				this.q *= -1;
			}
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + (int) (p ^ (p >>> 32));
			result = prime * result + (int) (q ^ (q >>> 32));
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Fraction other = (Fraction) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (p != other.p)
				return false;
			if (q != other.q)
				return false;
			return true;
		}

		private differ_ak getOuterType() {
			return differ_ak.this;
		}
		
		@Override
		public String toString() {
			return "<" + p + " / " + q + ">";
		}
		
	}
	
	void addPow(long a, long b) {
		if (a == 0 && b <= 0)
			return;
		if (a == 0) {
			h.add(new Fraction(0, 1));
			return;
		}
		if (a == 1) {
			h.add(new Fraction(1, 1));
			return;
		}
		if (a == -1) {
			h.add(new Fraction(b % 2 == 0 ? 1 : -1, 1));
			return;
		}

		double pow = Math.log(Math.abs(a)) * Math.abs(b);
		if (pow > 30) {
			h.add(new Fraction((long)1000000000 * 1000000000 * 2 - a + b, 1));
			return;
		}
		long p = 0;
		long q = 0;
		if (b > 0) {
			p = power(a, b);
			q = 1;
		} else {
			p = 1;
			q = power(a, -b);
		}
		if (b % 2 == 1 && b < 0) 
			p = -p;
		h.add(new Fraction(p, q));
	}
	
	
	long power(long a, long b) {
		long ret = 1;
		for (int i = 0; i < Math.abs(b); i++) {
			ret *= a;
		}
		return ret;
	}



	HashSet<Fraction> h;
	void solve() {
		long a = nextLong();
		long b = nextLong();
		h = new HashSet<Fraction>();
		h.add(new Fraction(a + b, 1));
		h.add(new Fraction(a - b, 1));
		h.add(new Fraction(b - a, 1));
		h.add(new Fraction(a * b, 1));
		if (b != 0)
			h.add(new Fraction(a, b));
		if (a != 0)
			h.add(new Fraction(b, a));
		addPow(a, b);
		addPow(b, a);
//		System.err.println(h);
		out.println(h.size());
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof;
	final Random rand = new Random(this.hashCode());

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

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

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

	BigInteger nextBigInteger() {
		return new BigInteger(nextToken());
	}

	differ_ak() {
		try {
			br = new BufferedReader(new FileReader("differ.in"));
			out = new PrintWriter("differ.out");
			solve();
			br.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "-1";
			}
		}
		return st.nextToken();
	}

	public static void main(String[] args) {
		new differ_ak();
	}
}
