import java.util.Scanner
 
fun main(args : Array<String>){
  val cin = Scanner(System.`in`)
  var n = cin.nextLong()
  var m = cin.nextLong()
  var res : Long
  if (n * 2L <= m){
    res = n
    m -= n * 2L
    res += m / 4L
  }
  else res = m / 2L
  println(res)
}