#include <bits/stdc++.h>
using namespace std;
template <class T>
void _print(T arg) {
  cout << arg << " ";
}
template <class... Args>
void log(Args... args) {
  int arr[] = {(_print(args), 0)...};
  cout << endl;
}
const int INF = 0x3f3f3f3f;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int dir[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const long long mod = 1e9 + 7;
const int base = 131;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int N = 1e6 + 10;
const int M = 1e5 + 10;
int a[N];
int ans = 0;
int n, m, k;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    a[i] = 2;
  }
  int sum = n * 2;
  for (int i = 1; i <= n; i++) {
    if (sum < k) a[i]++, sum++;
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 2) res++;
  }
  cout << res << endl;
  return 0;
}
