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