import io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toLong)
  val ans =
    if(n >= m / 2) m / 2
    else {
      val k = m - n * 2
      n + k / 4
    }
  println(ans)
}