/**
 * Created by yusaku on 2017/02/27.
 */

fun main(args: Array<String>) {
    val line = readLine()
    if (line != null) {
        val NM = line.split(" ").map(String::toLong)
        val s = NM[0]
        val c = NM[1]

        if (s * 2 <= c) {
            print(s + (c - 2 * s) / 4)
        } else {
            print(c / 2)
        }
    }
}
