using System; using static System.Console; using System.Linq; using System.Collections.Generic; using System.Runtime.Intrinsics.Arm; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static long[] LList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => long.Parse(ReadLine())).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var gcd = GCD(c[0], c[1]); if (gcd > 1) WriteLine(-1); else { var dp = new bool[c[0] * c[1] + 1]; for (var i = 0; i < c[1]; ++i) for (var j = c[0] * i; j < dp.Length; j += c[1]) dp[j] = true; var ans = 0; for (var i = 1; i < dp.Length; ++i) if (!dp[i]) ++ans; WriteLine(ans); } } static int GCD(int a, int b) { if (a < b) return GCD(b, a); if (a % b == 0) return b; return GCD(b, a % b); } }