import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); if (gcd(a, b) != 1) { System.out.println(-1); return; } int max = a * b; boolean[] check = new boolean[max + 1]; for (int i = 0; i * a <= max; i++) { for (int j = 0; i * a + j * b <= max; j++) { check[i * a + j * b] = true; } } int count = 0; for (int i = 1; i <= max; i++) { if (!check[i]) { count++; } } System.out.println(count); } static int gcd(int x, int y) { if (x % y == 0) { return y; } else { return gcd(y, x % y); } } }