import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  ulong[] NM = readln.chomp.split.to!(ulong[]);
  ulong n = NM[0],
        m = NM[1];
  ulong s, c;

  if (n <= m / 2) {
    writeln(n + (m - 2*n) / 4);
  } else {
    writeln(m / 2);
  }
}
