#include <iostream>
using namespace std;

int main() {
    long long N,M;
    cin >> N >> M;
    long long cc = M / 2;
    long long ans = min(N,cc);
    M -= ans * 2;
    ans += M / 4;
    cout << ans << endl;
}