import java.math.BigInteger; import java.util.Scanner; /** * Created by alex on 12.02.2016. */ public class prog { public static void main(String args[]) { Scanner in = new Scanner(System.in); BigInteger A, B; A = in.nextBigInteger(); B = in.nextBigInteger(); BigInteger sol = BigInteger.valueOf(-1); for (int i = 0; i < 120; ++i) for (int j = 0; j < 120; ++j) { BigInteger C = A; BigInteger D = B; C = C.subtract(BigInteger.valueOf(i)); D = D.subtract(BigInteger.valueOf(j)); if (C.compareTo(BigInteger.ZERO) > 0 && D.compareTo(BigInteger.ZERO) > 0) { BigInteger E = C.subtract(D); E = E.abs(); if (C.gcd(D).compareTo(BigInteger.valueOf(1)) == 0) sol = sol.max(E.add(BigInteger.ONE)); } } System.out.print(sol); } }