#include <stdio.h>

int main(void){
    int a, b;
    while(~scanf("%d%d", &a, &b)){
        int x = 0,c[100];
        for(int i = a;i <= 1018;i++){
            if(i % a == 0 && i % b != 0){
                c[x] = i;
                x++;
            }
        }
        if(x != 0)
            printf("%d\n", c[x/b]);
        if(x == 0)
            printf("-1\n");
    }
    return 0;
}
