Problem:
Score : 100 points

Problem Statement

You are given positive integers X and Y.
If there exists a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, choose one such integer and print it.
If it does not exist, print -1.

Constraints

1 ≤ X,Y ≤ 10^9

X and Y are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

Print a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, or print -1 if it does not exist.

Sample Input 1

8 6

Sample Output 1

16

For example, 16 is a multiple of 8 but not a multiple of 6.

Sample Input 2

3 3

Sample Output 2

-1

A multiple of 3 is a multiple of 3.

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

struct ContestPrinter {
    s: String,
}

impl ContestPrinter {
    fn new() -> ContestPrinter {
        ContestPrinter {
            s: String::new(),
        }
    }

    fn print<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}", x).as_str());
    }

    fn println<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}\n", x).as_str());
    }
}

impl std::ops::Drop for ContestPrinter {
    fn drop(&mut self) {
        print!("{}", self.s);
    }
}

fn main() {
    let mut printer = ContestPrinter::new();
    let n = readl!(usize);
    let mut dif = vec![0; n];
    for _ in 0..n-1 {
        let (a, b, c) = readl!(usize, usize, usize);
        dif[a] ^= c;
        dif[b] ^= c;
    }

    let mut imask = 0;
    let mut iv = 0;
    for i in 0..n {
        if dif[i] != 0 {
            if (imask>>dif[i])&1 == 1 {
                iv += 1;
            }
            imask ^= 1<<(dif[i]);
        }
    }
    let imask = imask;
    let iv = iv;
    let dma = dif.iter().map(|&x| x).max().unwrap()+1;
    
    let inf = 1_000_000_000;
    let mut dp = vec![inf; 1<<dma];
    // dp[imask] = iv;
    dp[0] = 0;
    for mask in 1..1<<dma {
        let mut pmask = 0;
        while pmask != mask {
            let sx = (0..dma).fold(0, 
                |sum, x| if (pmask>>x)&1 == 1 {sum^x} else {sum});
            if sx == 0 {
                dp[mask] = std::cmp::min(dp[mask], dp[pmask]+(pmask^mask).count_ones()-1);
            }
            pmask = ((pmask as i64-mask as i64) & mask as i64) as usize;
        }
    }

    printer.println(dp[imask]+iv);
}