function main()
  local input = string.gmatch(io.read(), "[^ ]+")
  local n = tonumber(input())
  local m = tonumber(input())

  local ans
  if n < 2*m then
    ans = n
  else
    ans = math.floor(m/2)
  end

  m = m - 2*ans

  ans = ans + math.floor(m/4)

  print(ans)
end

main()
