#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (k % n == 0) {
    if (k / n == 2)
      cout << n;
    else
      cout << 0;
  } else {
    if (k / n == 2)
      cout << (n - (k % n));
    else if ((k / n) + 1 == 2)
      cout << k % n;
    else
      cout << 0;
  }
  return 0;
}
