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