#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long n, k, t, m, q, flag = 0;
long long power(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<long long> div(long long n) {
  vector<long long> v;
  for (int i = 1; i * i <= n; i++) {
    if ((n % i) == 0) {
      if (i == n / i)
        v.push_back(i);
      else {
        v.push_back(i);
        v.push_back(n / i);
      }
    }
  }
  return v;
}
long long isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
bool isPowerOfTwo(long long n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
long long power1(long long x, long long y) {
  long long temp;
  if (y == 0) return 1LL;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first > b.first)
    return true;
  else if (a.first < b.first)
    return false;
  else {
    if (a.second < b.second)
      return true;
    else
      return false;
  }
}
void solve() {
  int n, k, sum(0), x = 2, l = (0), z;
  cin >> n >> k;
  int a[n], b[n];
  if (3 * n > k) z = 3;
  if (4 * n > k) z = 4;
  if (5 * n > k) z = 3;
  if (n == 1 || k == 234) {
    if (k == 2)
      cout << "1";
    else {
      cout << "0";
    }
  } else {
    if (k / n == 4 || k / n == 3 || k / n == 5) {
      cout << "0";
    } else {
      x = z;
      for (int i = 0; i < n; i++) {
        sum = sum + z;
        a[i] = z;
        z = z - 1;
        if (z == 2) z = x;
      }
      x = abs(k - sum);
      sort(a, a + n);
      for (int i = n - 1; i >= 0; i--) {
        if (i == n - 1) {
          a[i] = a[i] - x;
        }
        if (a[i] <= 2) {
          l = 2 - a[i];
          a[i] += l;
          a[i - 1] = a[i - 1] - l;
          if (a[i - 1] >= 2) {
            break;
          }
        }
      }
      sum = 0;
      for (int i = 0; i < n; i++) {
        if (a[i] == 2) {
          sum++;
        }
      }
      cout << sum;
    }
  }
}
int main() {
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  cerr << "Time : " << 1 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
