#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
	ll k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
ll n,m;
int main()
{
	n=read();m=read();
	ll ans=min(n,m/2);
	n-=ans;m-=ans*2;
	ans+=m/4;
	cout<<ans<<endl;
}