#include <bits/stdc++.h>
using namespace std;
int arr[251][251][51];
bool check(int n, int ans, int t) {
  if (t == 0) {
    if (ans == n) return 1;
    return 0;
  }
  bool ret = 0;
  if (arr[n][ans + 3][t - 1] == -1)
    arr[n][ans + 3][t - 1] = check(n, ans + 3, t - 1);
  ret |= arr[n][ans + 3][t - 1];
  if (arr[n][ans + 4][t - 1] == -1)
    arr[n][ans + 4][t - 1] = check(n, ans + 4, t - 1);
  ret |= arr[n][ans + 4][t - 1];
  if (arr[n][ans + 5][t - 1] == -1)
    arr[n][ans + 5][t - 1] = check(n, ans + 5, t - 1);
  ret |= arr[n][ans + 5][t - 1];
  return ret;
}
int main() {
  for (int i = 0; i < 251; i++)
    for (int ii = 0; ii < 251; ii++)
      for (int iii = 0; iii < 51; iii++) arr[i][ii][iii] = -1;
  int n, k;
  cin >> n >> k;
  for (int i = 0; i <= n; i++) {
    if (check(k - i * 2, 0, n - i)) {
      cout << i;
      return 0;
    }
  }
  cout << 0;
  return 0;
}
