#include<iostream>
using namespace std;

long long  N,M;
int main(){
    cin>>N>>M;
        if(2*N<=M){
            cout<<(N+(M-2*N)/4)<<endl;
        }else{
            cout<<M/2<<endl;
        }

    return 0;
}
