[step:Integrate the tail bound to estimate the expectation]
Let $\mathcal L^1$ denote one-dimensional [Lebesgue measure](/page/Lebesgue%20Measure) on $[0,\infty)$. Since $M$ is the finite maximum of measurable real-valued random variables, $M$ is measurable, and $M \ge 0$. The [layer-cake identity](/theorems/2956) for non-negative measurable random variables gives, with both sides allowed initially to take the value $+\infty$,
\begin{align*}
\mathbb E[M] = \int_0^\infty \mathbb P(M \ge t)\,d\mathcal L^1(t).
\end{align*}
Let
\begin{align*}
L := \log(N+1), \qquad a := K\sqrt{\log(2N)}.
\end{align*}
Using the tail estimate from the previous step and splitting the integral at $a$, we obtain
\begin{align*}
\mathbb E[M] \le \int_0^a 1\,d\mathcal L^1(t)+ \int_a^\infty 2N\exp\left(-\frac{t^2}{K^2}\right)\,d\mathcal L^1(t).
\end{align*}
For the second integral, the change of variables $t=Ks$ transforms $d\mathcal L^1(t)$ into $K\,d\mathcal L^1(s)$ and transforms the domain $[a,\infty)$ into $[\sqrt{\log(2N)},\infty)$. Hence
\begin{align*}
\mathbb E[M] \le a + K\int_{\sqrt{\log(2N)}}^\infty 2N e^{-s^2}\,d\mathcal L^1(s),
\end{align*}
where we used the change of variables $t=Ks$, so $d\mathcal L^1(t)=K\,d\mathcal L^1(s)$. For $s \ge \sqrt{\log(2N)}$, the Gaussian tail estimate
\begin{align*}
\int_r^\infty e^{-s^2}\,d\mathcal L^1(s) \le \frac{e^{-r^2}}{2r}
\end{align*}
with $r=\sqrt{\log(2N)}$ gives
\begin{align*}
K\int_{\sqrt{\log(2N)}}^\infty 2N e^{-s^2}\,d\mathcal L^1(s) \le K \cdot 2N \cdot \frac{e^{-\log(2N)}}{2\sqrt{\log(2N)}} = \frac{K}{2\sqrt{\log(2N)}}.
\end{align*}
Since $N \ge 1$, we have $\log(2N) \ge \log 2$, $\log(2N) \le 2\log(N+1)$, and $\log(N+1) \ge \log 2$. Therefore
\begin{align*}
\frac{K}{2\sqrt{\log 2}}
\le \frac{K\sqrt{\log(N+1)}}{2\log 2},
\end{align*}
and hence
\begin{align*}
\mathbb E[M] \le K\sqrt{2\log(N+1)} + \frac{K\sqrt{\log(N+1)}}{2\log 2} \le C_1 K\sqrt{\log(N+1)}
\end{align*}
for the universal constant
\begin{align*}
C_1 := \sqrt{2} + \frac{1}{2\log 2}.
\end{align*}
[/step]