#include<stdio.h>
#include<math.h>
#define max(a,b)(a>b?a:b)
//int a[100010];

  int main()
{
  double s,c,a;
  scanf("%lf %lf",&s,&c);
  if(floor(c / 2) < s)
    a = floor(c / 2);
  else
  {
    a = s;
    c = c - s - s;
    a = a + floor(c / 4);
  }

  printf("%.0lf\n",a);
  return 0;
 }
