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