#include <cstdio>

#define min(a, b) ((a) < (b) ? (a) : (b))

int main()
{
  long long n, m;
  scanf("%lld %lld", &n, &m);
  long long s = min(n, m / 2);
  printf("%lld\n", s + (m - 2 * s) / 4);
  return 0;
}
