#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  long long int max = n + (n - 1);
  long long int minn = 3;
  if (n == 1) {
    cout << "0";
  } else {
    if (k > max || k < minn) {
      cout << "0";
    } else {
      if (k == max || k == minn) {
        cout << "1";
      } else {
        if (k > n) {
          cout << (2 * n - k + 1) / 2;
        } else {
          cout << (k - 1) / 2;
        }
      }
    }
  }
  return 0;
}
