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