import java.util.Scanner

object Main {
  def solve(N: Long, M: Long): Long = {
    if (N * 2 >= M) M / 2
    else {
      val c = M - N * 2
      N + c / 4
    }
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextLong()
    val M = sc.nextLong()
    println(solve(N, M))
  }
}
