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