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