#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    long long n,m;
    cin>>n>>m;
    int sum=0;
    if(2*n>=m)
        printf("%d\n",n);
    else
        printf("%d\n",n+(m-n)/4);
}
