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