Scanf.scanf "%d %d" (fun n m ->
    let check c =
        let a = max (c - n) 0 in
        m - 2 * a >= 2 * c 
    in
    let rec loop l r =
        if l = r then l - 1 else
            let m = (l + r) / 2 in
            if check m then loop (m + 1) r else loop l m
    in
    loop 0 10000000000000 |> Printf.printf "%d\n"
)