using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Magatro { static void Main() { string[] q = Console.ReadLine().Split(' '); int n = int.Parse(q[0]); int d = int.Parse(q[1]); long ans = (LCM(n, d) / d) - 1; Console.WriteLine(ans); } static long LCM(int x,int y) { long a = Math.Max(x, y); long b = Math.Min(x, y); long q = a * b; long r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return q / b; } }