#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  while (cin >> n >> k) {
    bool can = false;
    int i = 0;
    int r1, r2;
    while (!can) {
      r1 = k - (2 * i);
      r2 = n - i;
      i++;
      if (r1 <= 5 * r2 && r1 >= 3 * r2) {
        i--;
        can = true;
      }
    }
    cout << i << endl;
  }
}
