#include <iostream>
#include <algorithm>
#include <set>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long ll;
int main()
{
   ll n,m,ans;
   cin>>n>>m;
   if(2*n>=m) ans=m/2;
   else{
     m=m-n*2;
     ans=n+m/4;
   }
   cout<<ans<<endl;
   return 0;
}
