import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val (n, m) = (sc.nextInt, sc.nextInt)
  val a = java.lang.Integer.min(n, m / 2)
  println(a + (m - 2 * a) / 4)
}
