#include <bits/stdc++.h>
using namespace std;
const int MAX = 500;
bool dp[MAX][MAX];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i * 2 <= k && i <= n; ++i) {
    int m = k - i * 2;
    memset(dp, 0, sizeof dp);
    dp[0][0] = true;
    for (int j = 1; j <= n - i; ++j)
      for (int p = 3; p < 6; ++p)
        for (int w = m; w > 0; --w)
          if (w >= p && dp[j - 1][w - p]) dp[j][w] = true;
    if (dp[n - i][m]) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}
