#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  if (m / n == 2)
    cout << n - m % n;
  else if (m / n == 1)
    cout << m % n;
  else
    cout << 0;
  return 0;
}
