#include <bits/stdc++.h>
using namespace std;
signed main() {
  int a, p;
  cin >> a >> p;
  a *= 3;
  p += a;
  if (p % 3 == 0) {
    cout << p / 2 << "\n";
  } else {
    if (p / 2 <= 0) {
      cout << "0\n";
    } else {
      cout << p / 2 - 1 << "\n";
    }
  }
}
