#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long LL;
int main()
{
	LL n,m;
	
	while(~scanf("%lld %lld",&n,&m))
	{
		LL ans = 0;
		if(n * 2 < m)
		{
			ans += n; 
		}
		else
		{
			printf("%lld\n",m/2);
			continue;
		}
		m -= n * 2;
		ans += m / 4;
		printf("%lld\n",ans);
	 } 
 } 