#include <bits/stdc++.h>
using namespace std;
const long long SuperINF = 1e9;
const long long MAX_SIZE = 4 * 1e5, MOD = 1e9 + 7;
const double eps = 1e-6;
void files() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
long long n, k;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  long long right, left;
  left = max((long long)1, k - n);
  right = k - left;
  cout << max((long long)0, (right - left + 1) / 2);
}
