#include <stdio.h>
#include <stdlib.h>

int main()
{
    int m,n,a,b,c;
    scanf("%d %d",&m,&n);
    if(m>=(n/2))
    a=m;
    else
    {
        b=n-2*m;
        c=b/4;
        a=m+c;
    }
    printf("%d\n",a);
    return 0;
}
