#include <bits/stdc++.h>
using namespace std;
int A[100], k, n;
int main() {
  int i, j;
  cin >> n >> k;
  int tmp = n * 2;
  int left = k - tmp;
  if (left >= n)
    cout << "0" << endl;
  else
    cout << n - left << endl;
  return 0;
}
