#include <bits/stdc++.h>
using namespace std;
int const INF = (1 << 30);
int const MAXN = (int)1e5 + 100;
int n, k;
int main() {
  cin >> n >> k;
  for (int x = 0; x <= n; x++) {
    for (int y = 0; y <= n; y++) {
      for (int z = 0; z <= n; z++) {
        for (int t = 0; t <= n; t++) {
          int q = 2 * x + 3 * y + 4 * z + 5 * t;
          if (q == k && x + y + z + t == n) {
            cout << x << endl;
            return 0;
          }
        }
      }
    }
  }
  return 0;
}
