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