#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int MAX = 100005;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  if (n == 1 or k < 3) {
    cout << 0 << endl;
    return 0;
  }
  if (n >= k) {
    k--;
    k /= 2;
    cout << k << endl;
    return 0;
  }
  if (n + n - 1 < k) {
    cout << 0 << endl;
    return 0;
  }
  if (n + 1 >= k) {
    k--;
    k /= 2;
    cout << k << endl;
    return 0;
  }
  long long m = k / 2;
  cout << n - m << endl;
  return 0;
}
