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