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