#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, x, y;
  cin >> a >> b;
  x = a * 2;
  if ((b - x) <= a) {
    y = a - b + x;
    cout << y << endl;
  } else
    cout << "0" << endl;
}
