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