#include <stdlib.h>
#include <string.h>
#include <math.h>
#define N 100
int main()
{
     long int   n,m,s,x;
     scanf("%ld%ld",&n,&m);
     if(2*n>=m)
     {
         s=m/2;
     }
    else
    {
        x=m-2*n;
        s=n+x/4;
    }
    printf("%ld",s);
    return 0;
}