import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long D = sc.nextLong(); System.out.println(N*gcd(N,D)-1); } public static long gcd(long N, long D){ while(D != 0){ long r = N % D; N = D; D = r; } return N; } }