#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (k == 1)
    cout << "0" << endl;
  else if (2 * n > k)
    cout << "0" << endl;
  else if (2 * n <= k && 3 * n > k)
    cout << n - (k - 2 * n) << endl;
  else
    cout << "0" << endl;
  return 0;
}
