Use Newton's second law and Newton's law of universal gravitation to find out the second cosmic speed (i.e. the escape speed).

There are many approaches how to determine second cosmic speed. We will describe the motion $y(t)$ by means of differential equation in order to demonstrate higher order nonlinear DE and then use to determine second cosmic speed..

Newton's second law says that when the sum of forces on a body is zero, then acceleration of the body is zero. Otherwise the net force is proportional to acceleration of the body.

The position $y(t)$ of the body can be described by DE $$ \begin{align} m\frac{d^2y}{dt^2} &= -mg \nonumber \\ \frac{d^2y}{dt^2} &= -g \nonumber \end{align} $$

So $mg$ above is force of gravity. The minus sign is necessary: we have taken the upward direction as positive. But earth's force of gravity does not act in such way.

Assuming we are able to solve DE including its constants (from initial values), then we have a description of motion as function of $t$. For a rocket motion, constant $g$ can not be viewed as a constant. We have to consider that far from the earth it is a function of $y$ (i.e. $g = f(y)$). The two bodies are attracted by a force

$$ F = k\frac{mM}{R^2} = k\frac{mM}{y^2} $$so we can rewrite gravitational acceleration as a function of distance:

$$ \frac{d^2y}{dt^2} = -k\frac{M}{y^2}. $$The constants $k,\ M$ are unwelcome and we can eliminated them. If $y=R$, then acceleration has a value of $g$ or $g= kM/R^2 \implies k = gR^2/M$.

$$ \begin{align} \frac{d^2y}{dt^2} = -g\frac{R^2}{y^2} \nonumber \\ y''y^2 = -g{R^2} \nonumber \end{align} $$It is nonlinear DE of the second order. Finally we will not solve for $y$ but only for speed $v$. Velocity $v = y'$.

$$ \begin{align} v'y^2 &= -gR^2, \hskip2em v = y' = \frac{dy}{dt}, \hskip2em v' = \frac{dv}{dy}\frac{dy}{dt} = \frac{dv}{dy}v \nonumber \\ \frac{dv}{dy}v\ y^2 &= -gR^2 \nonumber \\ dv\ v &= -gR^2 \frac{1}{y^2}dy \nonumber \\ \frac{v^2}{2} &= gR^2\frac{1}{y} + c_1 \nonumber \\ v^2 &= 2gR^2\frac{1}{y} + 2c_1 \nonumber \\ v &= \sqrt{2gR^2\frac{1}{y} + 2c_1} \nonumber \\ \end{align} $$We have employed chain rule in order to solve DE. So far we have speed $v$ as a function of distance $y$. The constant $c_1$ can be determined from the initial value: on the surface of the earth ($y=R$) the body has an initial speed $v_0$:

$$ \begin{align} v_0 &= \sqrt{2gR^2\frac 1 R + 2c_1} \nonumber \\ v_0^2 &= 2gR + 2c_1 \nonumber \\ c_1 &= \frac{v_0^2}{2} - gR \nonumber \end{align} $$Thus we have

$$ v(y) = \sqrt{\color{red}{2gR^2\frac 1 y} +2\big(\color{blue}{\frac{v_0^2}{2}-gR\big)}} $$Now we are back to the question from the beginning. What is the second cosmic speed? What *initial speed* the
body needs to be given, that the gravitational forces are not able to call the body back to
the earth.

At any point ($y \to \infty$) on the body's trip the body has not to stop. The speed $v(y)$ have to be always greater than zero. At such large distance ($y \to \infty$) the member $2gR^2/y$ is zero. Then the speed $v(y)$ is greater than zero if

$$ \frac{v_0^2}{2} \gt gR \implies \underline{\underline{v_0> \sqrt{2gR} = 11.2\ \text{km/s}}} $$So, if you want to escape the earth, you have to do it pretty quickly. Note: it can be shown that the second cosmic velocity does not require direction perpendicular to earth surface.