import Foundation
 
struct StdIn {
    static var data: NSData {
         return NSFileHandle.fileHandleWithStandardInput().readDataToEndOfFile()
    }
    static var string: String {
        return  String(data:data, encoding:NSUTF8StringEncoding) ?? ""
    }
    static var lines: [String] {
        return string.componentsSeparatedByString("\n")
    }
}
 
extension String {
   func tokens(delimter: String = " ") -> [String] {
       return self.componentsSeparatedByString(delimter)
   }
}

func hoge() {
let nums = StdIn.string.tokens().flatMap { Int($0) }
if nums.count != 2 { fatalError(); return }

let x = nums[0]
let y = nums[1]

if x == 0 || y == 0 { print(-1); return }

if y % x == 0 {
  print(-1)
  return
}

let hoge = (2..<10000000000)
  .lazy
  .filter { n in
    return ((x * n) % y != 0)
  }
  .first ?? -1
if hoge == -1 {
    print(-1)
} else {
   print(x * hoge)
}
}

hoge()