#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main () {
    int A, B ;
    long long X, Y, i ;
    X = -1 ;
    scanf ( "%d %d", &A, &B ) ;
    Y = A * B ;
    for ( i = A ; i < Y; i += A ) {
        if ( A == 0 || B == 0 ) {
            break ;
        }
        if ( i % B != 0 ) {
            X = i ;
            break ;
        }
    }
    printf ( "%lld\n", X ) ;
    return 0 ;
}
