#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, y, arr[51] = {0};
  cin >> n >> y;
  int i = 0;
  while (y) {
    if (i == n) i = 0;
    arr[i]++;
    i++;
    y--;
  }
  int count = 0;
  for (i = 0; i < n; i++)
    if (arr[i] == 2) count++;
  cout << count << endl;
  return 0;
}
