Assume that there is a set of monic polynomials $P_n(z)$ satisfying the second-order difference equation $$ A(s) P_n(z(s+1)) + B(s) P_n(z(s)) + C(s) P_n(z(s-1)) = \lambda_n P_n(z(s)), n=0,1,2,..., N$$ where $z(s), A(s), B(s), C(s)$ are some functions of the discrete argument $s$ and $N$ may be either finite or infinite. The irreducibility condition $A(s-1)C(s) \ne 0$ is assumed for all admissible values of $s$. In the finite case we assume that there are $N+1$ distinct grid points $z(s), \: s=0,1,..., N$ such that $z(i) \ne z(j), \: i \ne j$. If $N=\infty$ we assume that the grid $z(s)$ has infinitely many different values for different values of $s$. In both finite and infinite cases we assume also that the problem is non-degenerate, i.e. $\lambda_n \ne \lambda_m, n \ne m$. Then we show that necessarily: (i) the grid $z(s)$ is at most quadratic or q-quadratic in $s$; (ii) corresponding polynomials $P_n(z)$ are at most the Askey-Wilson polynomials corresponding to the grid $z(s)$. This result can be considered as generalizing of the Bochner theorem (characterizing the ordinary classical polynomials) to generic case of arbitrary difference operator on arbitrary grids.