#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
bool isSquare(long long a) {
  long long b = sqrt(a);
  return b * b == a;
}
long long gcd(long long a, long long b) {
  long long t;
  while (b != 0) {
    t = b;
    b = a % b;
    a = t;
  }
  return a;
}
long long lcm(long long a, long long b) {
  if (a > b)
    return (a / gcd(a, b)) * b;
  else
    return (b / gcd(a, b)) * a;
}
long long modBigNumber(string num, long long m) {
  vector<int> vec;
  long long mod = 0;
  for (int i = 0; i < num.size(); i++) {
    int digit = num[i] - '0';
    mod = mod * 10 + digit;
    int quo = mod / m;
    vec.push_back(quo);
    mod = mod % m;
  }
  return mod;
}
vector<int> prime_factors(long long n) {
  vector<int> v;
  while (n % 2 == 0) {
    v.push_back(2);
    n /= 2;
  }
  for (int i = 3; i * i <= n; i += 2) {
    while (n % i == 0) {
      v.push_back(i);
      n /= i;
    }
  }
  if (n > 2) v.push_back(n);
  return v;
}
set<int> dist_prime_factors(long long n) {
  set<int> v;
  while (n % 2 == 0) {
    v.insert(2);
    n /= 2;
  }
  for (int i = 3; i * i <= n; i += 2) {
    while (n % i == 0) {
      v.insert(i);
      n /= i;
    }
  }
  if (n > 2) v.insert(n);
  return v;
}
vector<int> getDivisors(int n) {
  vector<int> v;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i)
        v.push_back(i);
      else {
        v.push_back(i);
        v.push_back(n / i);
      }
    }
  }
  sort(v.begin(), v.end());
  return v;
}
int ind_binary_search(vector<int> v, int l, int r, int x) {
  while (l <= r) {
    int m = l + (r - l) / 2;
    if (v[m] == x) return m;
    if (v[m] < x)
      l = m + 1;
    else
      r = m - 1;
  }
  return -1;
}
void swap(int* a, int* b) {
  int t = *a;
  *a = *b;
  *b = t;
}
int isSubstring(string s1, string s2) {
  int M = s1.length();
  int N = s2.length();
  for (int i = 0; i <= N - M; i++) {
    int j;
    for (j = 0; j < M; j++)
      if (s2[i + j] != s1[j]) break;
    if (j == M) return i;
  }
  return -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  if (k >= n * 3)
    cout << 0;
  else
    cout << n - (k % n);
  return 0;
}
