#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, p;
  cin >> a >> p;
  p += a * 3;
  int apple = 0;
  while (1) {
    if (p >= 3) {
      p -= 2;
      apple++;
    } else
      break;
  }
  cout << apple << endl;
}
