#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
int main()
{
    ll s,c,cc;
    scanf("%lld%lld",&s,&c);
    cc=c/2;
    if(s>cc) printf("%lld",cc);
    else if(s==cc)
    {
        printf("%lld\n",cc);
    }
    else
    {
        for(;s<cc;s++,cc--);
            printf("%lld\n",cc);
    }
    return 0;
}
