using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace tes { class contest { static void Main(string[] args) { var num = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Console.WriteLine(num[0]/gcd(num[0],num[1])-1); } static int gcd(int a, int b) { return (a % b == 0) ? a : gcd( b, a%b); } } }