import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!long);
    auto N = s[0];
    auto K = s[1];

    long x = K % 2 == 1 ? K / 2 : K / 2 - 1;
    x += 1;
    long hi = x;
    long lo = 0;

    while (hi - lo > 1) {
        long m1 = (hi + lo) / 2;
        long m2 = K - m1;
        if (m1 < m2 && m2 <= N) {
            hi = m1;
        } else {
            lo = m1;
        }
    }

    writeln(x - hi);
}
