"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    let S = parseInt(arg[0].split(" ")[0]);
    let C = Math.floor(parseInt(arg[0].split(" ")[1]));
    
    let cnt = 0;
   
    for(let i=1; i<=S; i++) {
        if(C > 2) {
            cnt++;
            C -= 2;
        }
    }
    
    cnt += Math.floor(C / 4);

    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));