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(); var dp = new bool[num[0]]; dp[1] = true; int count = 0; for(int i = 1+num[1]; i<=1000000000; i+=num[1]) { if (dp[i % num[0]] == true) break; else { dp[i % num[0]] = true; count++; } } Console.WriteLine(count); } } }