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