For $i=1,\ldots,r,\;$ define event $B_i = \text{"First tail occurs on $i^{th}$ toss"}$. Since the process ends after $r$ successive heads then, given initially that $A=H$, exactly one of these $r$ events must occur.
Note that, given $A=H$, if $B_r$ occurs then $E$ also occurs, which is to say $P(E\mid B_r\cap A=H) = 1$. Also, given $A=H$, if any of the other $B_i$ events occur then it is like we are starting over but, instead, initially given $A=T$. Therefore, conditioning on whether or not $B_r$ occurs,
\begin{eqnarray*}
P(E\mid A=H) &=& P(E\mid B_r\cap A=H)P(B_r\mid A=H) + P(E\mid B_r^c\cap A=H)P(B_r^c\mid A=H) \\
&& \\
&=& p^{r-1} + P(E\mid A=T)(1-p^{r-1}). \qquad\qquad\qquad\qquad\qquad(1) \\
\end{eqnarray*}
$\\$
Next, we can find $P(E\mid A=T)$ by way of $P(E^c\mid A=T)$ and that is found in a similar way to $P(E\mid A=H)$.
For $i=1,\ldots,s,\;$ define event $C_i = \text{"First head occurs on $i^{th}$ toss"}$. Then,
\begin{eqnarray*}
P(E\mid A=T) &=& 1 - P(E^c\mid A=T) \\
&& \\
&=& 1 - [P(E^c\mid C_r\cap A=T)P(C_r\mid A=T) + P(E^c\mid C_r^c\cap A=T)P(C_r^c\mid A=T)] \\
&& \\
&=& 1 - [1\cdot (1-p)^{s-1} + P(E^c\mid A=H)(1-(1-p)^{s-1})] \\
&& \\
&=& 1 - [(1-p)^{s-1} + (1 - P(E\mid A=H))(1-(1-p)^{s-1})] \\
&& \\
&=& (1-(1-p)^{s-1}) P(E\mid A=H). \qquad\qquad\qquad\qquad\qquad(2) \\
&& \\
\end{eqnarray*}
We now proceed to find $P(E)$. Substitute $(2)$ into $(1)$:
\begin{eqnarray*}
P(E\mid A=H) &=& p^{r-1} + (1-p^{r-1}) (1-(1-p)^{s-1}) P(E\vert A=H) \\
&& \\
\therefore P(E\mid A=H) &\times& (p^{r-1} - p^{r-1}(1-p)^{s-1} + (1-p)^{s-1}) \;\; = \;\; p^{r-1} \\
&& \\
P(E\mid A=H) &=& \dfrac{p^{r-1}}{p^{r-1} - p^{r-1}(1-p)^{s-1} + (1-p)^{s-1}} \qquad\qquad\qquad(3) \\
\end{eqnarray*}
Substitute this into $(2)$:
\begin{eqnarray*}
P(E\mid A=T) &=& \dfrac{p^{r-1} - p^{r-1} (1-p)^{s-1}}{p^{r-1} - p^{r-1}(1-p)^{s-1} + (1-p)^{s-1}} \qquad\qquad\qquad(4) \\
\end{eqnarray*}
$\\$
Finally, using results $(3)$ and $(4)$,
\begin{eqnarray*}
P(E) &=& P(E\mid A=H)P(A=H) + P(E\mid A=T)P(A=T) \\
&& \\
&=& \dfrac{p^r + p^{r-1}(1-p) - p^{r-1} (1-p)^s}{p^{r-1} - p^{r-1}(1-p)^{s-1} + (1-p)^{s-1}} \\
&& \\
&=& \dfrac{p^{r-1} - p^{r-1} (1-p)^s}{p^{r-1} - p^{r-1}(1-p)^{s-1} + (1-p)^{s-1}}.
\end{eqnarray*}