#include <bits/stdc++.h>
using namespace std;
const unsigned long long MOD = 1e9 + 7;
const int INF = (int)2e9 + 7;
const long long LINF = (long long)1e18;
const unsigned long long mod1 = 183453789;
const unsigned long long mod2 = 1234567891;
const int P1 = 337, P2 = 263;
template<typename T>
T input(){
T ans = 0, m = 1; char c = ' ';
while (!((c >= '0' && c <= '9') || c == '-')) c = getchar();
if (c == '-') m = -1, c = getchar();
while (c >= '0' && c <= '9') ans = ans * 10 + (c - '0'), c = getchar();
return ans * m;
}
string nextString(bool flag = false){
char ch; string ans = "";
do { ch = getchar(); } while(ch <= ' ');
while(1) {
ans += ch; ch = getchar();
if ( (!flag && ch <= ' ') || (flag && ch < ' ') ) break;
}
return ans;
}
char nextChar(){
char ch;
do {ch = getchar(); } while(ch <= ' ');
return ch;
}
void read(string& s){ s = nextString(); }
void read(char& c){ c = nextChar(); }
template<typename T> void read(T& a){ a = input<T>(); }
template<typename T, typename... R> void read(T& a, R&... r){ read(a); read(r...); }
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
freopen("pairs.in", "r", stdin);
freopen("pairs.out", "w", stdout);
#endif
long long n, k;
read(n, k);
long long l;
if (k & 1){
l = (k - 1) / 2;
} else {
l = k / 2;
}
cout << max(0LL, min(l - (k % 2 == 0), n - l));
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAgIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCB1bnNpZ25lZCBsb25nIGxvbmcgTU9EID0gMWU5ICsgNzsKY29uc3QgaW50IElORiA9IChpbnQpMmU5ICsgNzsKY29uc3QgbG9uZyBsb25nIExJTkYgPSAobG9uZyBsb25nKTFlMTg7CmNvbnN0IHVuc2lnbmVkIGxvbmcgbG9uZyBtb2QxID0gMTgzNDUzNzg5Owpjb25zdCB1bnNpZ25lZCBsb25nIGxvbmcgbW9kMiA9IDEyMzQ1Njc4OTE7CmNv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