main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  print $ solve n m

solve n m =
  let
    halfm = div m 2
  in
    if n < halfm then
      n + ((halfm-n) `div` 2)
    else
      halfm