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

int main()
{
    long long m,n;
    scanf("%lld%lld",&n,&m);

    while(n<m/2)
    {
        n++;
        m=m-2;
    }
    printf("%lld\n",m/2);
    return 0;
}
