
 //In The Name Of GOD
 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

const int mod = 998244353;
const int inf = 2000000000;
const int maxn = 500*1000+500*1000+15;
const int MLOG = 18;

#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())

int main(){
	int n, m;
	cin >> n >> m;
	if( m >= 2*n ){
		cout << n + (m-2*n)/4;
	}else{
		cout << m/2;
	}	
}
