  We consider the KZ equations over $\mathbb C$ in the case, when the
hypergeometric solutions are hyperelliptic integrals of genus $g$. Then the
space of solutions is a $2g$-dimensional complex vector space. We also consider
the same equations modulo $p^s$, where $p$ is an odd prime and $s$ is a
positive integer, and over the field $\mathbb Q_p$ of $p$-adic numbers. We
construct polynomial solutions of the KZ equations modulo $p^s$ and study the
space $\mathcal M_{p^s}$ of all constructed solutions. We show that the
$p$-adic limit of $\mathcal M_{p^s}$ as $s\to\infty$ gives us a $g$-dimensional
vector space of solutions of the KZ equations over $\mathbb Q_p$. The solutions
over $\mathbb Q_p$ are power series at a certain asymptotic zone of the KZ
equations.
  In the appendix written jointly with Steven Sperber we consider all
asymptotic zones of the KZ equations in the case $g=1$ of elliptic integrals.
The $p$-adic limit of $\mathcal M_{p^s}$ as $s\to \infty$ gives us a
one-dimensional space of solutions over $\mathbb Q_p$ at every asymptotic zone.
We apply Dwork's theory and show that our germs of solutions over $\mathbb Q_p$
defined at different asymptotic zones analytically continue into a single
global invariant line subbundle of the associated KZ connection. Notice that
the corresponding KZ connection over $\mathbb C$ does not have proper
nontrivial invariant subbundles, and therefore our invariant line subbundle is
a new feature of the KZ equations over $\mathbb Q_p$. We describe the Frobenius
transformations of solutions of the KZ equations for $g =1$ and then recover
the unit roots of the zeta functions of the elliptic curves defined by the
equations $y^2= \beta \,x(x-1)(x-\alpha)$ over the finite field $\mathbb F_p$.
Here $\alpha,\beta\in\mathbb F_p^\times, \alpha \ne 1$.
