#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k, i = 0, j = 0, sum = 0, count = 0;
  cin >> n >> k;
  int list[50];
  while (i < n) {
    list[i] = 2;
    sum += 2;
    i++;
  }
  while (sum != k) {
    if (j == n) j = 0;
    list[j] += 1;
    sum += 1;
    j++;
  }
  for (int k = 0; k < n; k++) {
    if (list[k] == 2) {
      count += 1;
    }
  }
  cout << count << endl;
  return 0;
}
