#include<stdio.h>

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