#include<stdio.h>
#include<math.h>
int main()
{
	long long int n,m,x,y;
	scanf("%lld%lld",&n,&m);
	if(m/2<=n)printf("%lld",m/2);
	else if(m/2>n)
	{
		x=m-n*2;
		y=x/4;
		printf("%lld",y+n);
	}
	return 0;
}