#include <bits/stdc++.h>
using namespace std;
int dp[55][255];
void min(int &a, int b) {
  if (a == -1) a = b;
  if (a > b) a = b;
}
int main(int argc, char *argv[]) {
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i <= 50; i++)
    for (int j = i; j <= 250; j++)
      if (dp[i][j] != -1) {
        min(dp[i + 1][j + 2], dp[i][j] + 1);
        for (int k = 3; k <= 5; k++) min(dp[i + 1][j + k], dp[i][j]);
      }
  int n, k;
  while (cin >> n >> k) cout << dp[n][k] << endl;
  return EXIT_SUCCESS;
}
