Elliptic Curve Digital Signature algorithm fails I would like to monitor step by step running of ECDSA.

Parameters I am working on:


The elliptic curve satisfies the equation: $y^2 = x^3 + x + 1$.
I picked up the base point $G$ as: $(0, 1)$
Finally, the modulo $p$ is $977$


My private key is $19$. Thereby, my public key is equal to $19\times G$ and its coordinates are $(396, 650)$. Suppose that my hash is equal to $14$.

Then, I picked up a random key. It would be $17$. So, random point would be $17\times G$ and it is equal to $(699, 739)$.

My signature is pair of $r$ and $s$, where $r$ is $x$ coordinate of my random point, and $s$ can be calculated as:
$$\begin{align}
r &amp;= 699\\
s &amp;= ((\text{random key})^{-1} \bmod p)\cdot(\text{hash} + r \cdot (\text{my private key}))\\
&amp;= (17^{-1}\bmod 977)\cdot(14 + 699\cdot19)\bmod 977\\
&amp;= (115\cdot13295)\bmod977\\
&amp;= 1528925\bmod977\\
&amp;= 897
\end{align}$$
So, my signature is $(699, 897)$.

Let's verify the signature
$$\begin{align}
w &amp;= s^{-1}\bmod p\\
&amp;= 897^{-1}\bmod 977\\
&amp;= 403\\
u_1 &amp;= \text{hash} \cdot w \bmod p\\
&amp;= 14 \cdot 403 \bmod 977\\
&amp;= 5642 \bmod 977\\
&amp;= 757\\
u_2 &amp;= r \cdot w \bmod p\\
&amp;= 7699 \cdot 403 \bmod 977\\
&amp;= 281697 \bmod977\\
&amp;= 321
\end{align}$$

Now, I calculate the checkpoint
$$\begin{align}
\text{checkpoint}&amp;=u_1\times G + u_2\times(\text{public key})\\
&amp;= 757\times(0, 1) + 321\times(396, 650)\\
&amp;=(707, 48)
\end{align}$$

Finally, I need to compare the $x$ coordinate of checkpoint and $r$ value of signature. But $x$ coordinate of checkpoint is $707$ whereas $r$ value was $699$. They are not same. This means that signature is invalid. But they should be equal! Anyone can help where I am wrong?
In the question, $p$ designates the modulus of the base field $\mathbb Z_p$, as confirmed by the fact that for  $p=977$ and the curve $y^2\equiv x^3+x+1\pmod p$, it holds that $19\times(0,1)=(396,650)$ and $17\times(0,1)=(699,739)$.
Problem is, in other steps, the question reduces $r$, $s$ and related quantities modulo that same $p$, rather than modulo the order $n$ of the group generated by $G$. That's more than enough to cause the observed failure.
As an aside, the ECDSA specification requires that $n$ is prime . In the question, the curve and $G$ is such that $n=987=3\cdot7\cdot47$ is composite. One consequence is that nearly half the choices of $\text{random key}$ are invalid, and I'm uncertain about if it otherwise makes some signature unverifiable. We do not care about the possible security implications since $p$ is so small as to make the whole thing insecure anyway.
I suggest $p=1033$, which will give a prime $n=1061$.