#include <bits/stdc++.h>
int main() {
  int i, j, k, l, m, n, a[100], sum, count = 0;
  scanf("%d%d", &n, &k);
  sum = 2 * n;
  for (i = 0; i < n; i++) {
    a[i] = 2;
  }
  i = 0;
  while (sum < k) {
    if (a[i] < 6) {
      a[i]++;
      i = (i + 1) % n;
    } else {
      i++;
      a[i]++;
      i = (i + 1) % n;
    }
    sum = sum + 1;
  }
  for (i = 0; i < n; i++) {
    if (a[i] == 2) count++;
  }
  printf("%d", count);
  return 0;
}
