#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int k;
  cin >> n >> k;
  int tows = 0;
  tows = n;
  k = k - n * 2;
  int threes = k > n ? n : k;
  tows -= threes;
  cout << tows;
}
