#include <bits/stdc++.h>
using namespace std;
template <typename T>
void alert(const T &t) {
  cout << t;
  exit(0);
}
template <typename T>
inline void alert(vector<T> &t, char delim = ' ') {
  for (T const &ti : t) cout << ti << delim;
  exit(0);
}
const long long MOD = 1e9 + 7;
vector<long long> Z(string s) {
  vector<long long> z(s.size());
  long long l = 0, r = 0;
  for (long long i = 1; i < z.size(); i++) {
    if (i >= l && i < r) {
      z[i] = min(z[i - l], r - i);
    }
    while (i + z[i] < z.size() && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] > r) {
      l = i;
      r = i + z[i];
    }
  }
  return z;
}
long long nod(long long a, long long b) {
  if (a > b) swap(a, b);
  while (a > 0) {
    b %= a;
    swap(a, b);
  }
  return b;
}
struct ost_vec {
  vector<long long> vec;
  ost_vec() {}
  ost_vec(long long x) { vec.resize(x); }
  ost_vec operator+(ost_vec const &x) {
    long long size = max(this->vec.size(), x.vec.size());
    ost_vec res(size);
    for (long long i = 0; i < size; i++) {
      if (i < this->vec[i]) res.vec[i] += this->vec[i];
      if (i < x.vec.size()) res.vec[i] += x.vec[i];
      res.vec[i] %= MOD;
    }
    for (long long i = 0; i < this->vec.size(); i++) {
      for (long long j = 0; j < x.vec.size(); j++) {
        res.vec[(i + j) % size] =
            (res.vec[(i + j) % size] + this->vec[i] * x.vec[j]) % MOD;
      }
    }
    return res;
  }
};
template <typename T>
struct Tree {
  vector<T> tree;
  long long size;
  long long n;
  Tree(long long x) {
    n = x;
    size = n * 4;
    tree.resize(size);
  }
  void Set(T val, long long x) { set(val, x, 0, n, 1); }
  void set(T &val, long long x, long long l, long long r, long long cur) {
    if (r - l == 1) {
      tree[cur] = val;
      return;
    }
    if (x < (l + r) / 2) {
      set(val, x, l, (l + r) / 2, cur * 2);
    } else {
      set(val, x, (l + r) / 2, r, cur * 2 + 1);
    }
    tree[cur] = tree[cur * 2] + tree[cur * 2 + 1];
  }
  T Sum(long long l, long long r) { return sum(l, r, 0, n, 1); }
  T sum(long long l, long long r, long long nl, long long nr, long long cur) {
    if (l == nl && r == nr) {
      return tree[cur];
    }
    T res;
    if (l < (nr + nl) / 2) {
      if (r <= (nr + nl) / 2) {
        return sum(l, r, nl, (nr + nl) / 2, cur * 2);
      } else {
        return sum(l, (nr + nl) / 2, nl, (nr + nl) / 2, cur * 2) +
               sum((nr + nl) / 2, r, (nr + nl) / 2, nr, cur * 2 + 1);
      }
    } else {
      return sum(l, r, (nr + nl) / 2, nr, cur * 2 + 1);
    }
  }
};
int main() {
  {
    if ("TASKNAME" != "TASKNAME") {
      freopen(
          "TASKNAME"
          ".in",
          "r", stdin);
      freopen(
          "TASKNAME"
          ".out",
          "w", stdout);
    } else if ("TASKNAME" == "1") {
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    }
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long ans;
  if (k <= n) {
    ans = (k - 1) / 2;
  } else {
    ans = k - n;
    if (ans > n) {
      ans = 0;
    } else {
      ans = n - ans + 1;
      ans /= 2;
    }
  }
  cout << ans;
  return 0;
}
