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