#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long

LL n, m;

int main() {
    cin>>n>>m;
    if( 2*n >= m ) {
        cout<<m/2<<endl;
    } else {
        LL ans = n;
        m -= 2*n;
        ans += m/4;
        cout<<ans<<endl;
    }
}
