#include <bits/stdc++.h>
using namespace std;
int main()
{
    int m, n;
    cin >> n >> m;
    int count = 0;
    while (n != 0 && m > 1)
    {
        if (n <= 2*m)
        {
            count += n;
            m -= 2 * n;
            n = 0;
        }
        if (m >= 2)
        {
            n ++;
            m -= 2;
        }
    }
    printf("%d\n",count);
    return 0;
}
