import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int a = sc.nextInt(); int b = sc.nextInt(); if (getGCD(a, b) > 1) { System.out.println(-1); return; } boolean[] enables = new boolean[a * b * 2 + 1]; for (int i = 0; i <= b; i++) { for (int j = 0; j <= a; j++) { enables[i * a + j * b] = true; } } int count = 0; for (int i = 0; i < a * b; i++) { if (!enables[i]) { count++; } } System.out.println(count); } static int getGCD(int x, int y) { if (x % y == 0) { return y; } else { return getGCD(y, x % y); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }