#include <bits/stdc++.h>
using namespace std;
int i, n, k;
int main() {
  cin >> n >> k;
  for (i = 0; i <= n; i++) {
    if (3 * (n - i) <= (k - 2 * i) && 5 * (n - i) >= (k - 2 * i)) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
