#include <bits/stdc++.h>
using namespace std;
int dp[4001];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int temp = k / n;
  if (temp < 2 || temp >= 3) {
    cout << 0 << endl;
    return 0;
  }
  cout << (3 * n - k) << endl;
  return 0;
}
