#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
long long a[N];
int main() {
  int n, k;
  while (~scanf("%d%d", &n, &k)) {
    int tmp = 2 * n;
    int b = k - tmp;
    if (tmp >= k)
      printf("%d\n", n);
    else {
      if (b < n)
        printf("%d\n", n - b);
      else
        printf("0\n");
    }
  }
  return 0;
}
