#import <stdio.h>
typedef long long INT;
int main(){
    INT N,M;
    scanf("%lld %lld",&N,&M);
    INT result = 0;
    if (M<=2*N) {
        result = M/2;
    } else {
        result = N;
        M -= 2*N;
        result += M/4;
    }
    printf("%lld", result);
}
