#include <bits/stdc++.h>
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) != EOF) {
    int sum;
    if (3 * n <= k)
      sum = 0;
    else
      sum = n - (k - 2 * n);
    printf("%d\n", sum);
  }
  return 0;
}
