#include<iostream>
#include <map>
#include <cstring>
using namespace std;
int main(void){
	long long n,m;
	cin>>n>>m;
	if (n>=m/2) cout<<m/2<<endl;
	else {
		long long x;
		m=m-2*n;
		m=m/4;
		cout<<m+n<<endl;
	}
}