#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int res, n, k;
  cin >> n >> k;
  for (int a = 0; a <= k / 5; a++)
    for (int b = 0; b <= k / 4; b++)
      for (int c = 0; c <= k / 3; c++) {
        if (a + b + c <= n &&
            (5 * a + 4 * b + 3 * c + (n - a - b - c) * 2) == k) {
          res = min(res, (n - a - b - c));
        }
      }
  cout << res << endl;
  return 0;
}
