#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, k, m;
  cin >> n >> k;
  if (k >= 3 * n) {
    cout << "0\n";
    return 0;
  }
  if (k <= 2 * n) {
    cout << n << "\n";
    return 0;
  }
  m = 3 * n - k;
  cout << m << '\n';
  return 0;
  return 0;
}
