fun main(arg: Array<String>) {
    val (N, M) = listOfLong()
    val ans = if (N * 2 <= M) N + (M - N * 2) / 4 else M / 2
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
