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