For every positive integer $M \geq  2$, find the smallest real number $C_M$ such that for any integers $a_1, a_2,\ldots , a_{2023}$, there always exist some integer $1 \leq k < M$ such that

\[\left\{\frac{ka_1}{M}\right\}+\left\{\frac{ka_2}{M}\right\}+\cdots+\left\{\frac{ka_{2023}}{M}\right\}\leq C_M.\]
Here, $\{x\}$ is the unique number in the interval $[0, 1)$ such that $x - \{x\}$ is an integer.
[i]
Proposed by usjl[/i]
To solve this problem, we need to find the smallest real number \( C_M \) such that for any integers \( a_1, a_2, \ldots, a_{2023} \), there always exists some integer \( 1 \leq k < M \) such that
\[
\left\{\frac{ka_1}{M}\right\} + \left\{\frac{ka_2}{M}\right\} + \cdots + \left\{\frac{ka_{2023}}{M}\right\} \leq C_M.
\]
Here, \(\{x\}\) denotes the fractional part of \(x\), which is the unique number in the interval \([0, 1)\) such that \(x - \{x\}\) is an integer.

1. **Expected Value Calculation**:
   Define the sum when we plug in \(k\) to be \(F(k)\). We need to calculate the expected value of \(F(k)\):
   \[
   F(k) = \left\{\frac{ka_1}{M}\right\} + \left\{\frac{ka_2}{M}\right\} + \cdots + \left\{\frac{ka_{2023}}{M}\right\}.
   \]
   Since \(\{x\}\) is uniformly distributed over \([0, 1)\), the expected value of \(\{x\}\) is \(\frac{1}{2}\). Therefore, the expected value of \(F(k)\) is:
   \[
   E[F(k)] = 2023 \cdot \frac{1}{2} = 1011.5.
   \]

2. **Bounding \(C_M\)**:
   We need to show that there exists some \(k\) such that \(F(k) \leq 1011 + \frac{1}{M}\). Assume for contradiction that \(F(k) > 1011 + \frac{1}{M}\) for all \(1 \leq k < M\).

3. **Sum of \(F(k)\) and \(F(M-k)\)**:
   Notice that \(F(k) + F(M-k)\) is an integer because:
   \[
   \left\{\frac{ka_i}{M}\right\} + \left\{\frac{(M-k)a_i}{M}\right\} = 1 \quad \text{if} \quad \left\{\frac{ka_i}{M}\right\} \neq 0,
   \]
   and
   \[
   \left\{\frac{ka_i}{M}\right\} + \left\{\frac{(M-k)a_i}{M}\right\} = 0 \quad \text{if} \quad \left\{\frac{ka_i}{M}\right\} = 0.
   \]
   Therefore, \(F(k) + F(M-k) \geq 2023\).

4. **Case Analysis**:
   - **Case 1: \( \gcd(M, P) = 1 \)**:
     There exists some \(k\) such that the fractional part of \(F(k)\) is \(\frac{1}{M}\). Hence, for that \(k\), \(F(k) + F(M-k) \geq 2024\). This implies that the average of all \(F(k)\) is more than \(1011 + \frac{1}{2}\), which is a contradiction.
   
   - **Case 2: \( \gcd(M, P) > 1 \)**:
     There exists \(k\) such that \(F(k)\) is an integer. Hence, \(F(k) + F(M-k) \geq 2024\). This leads to the same contradiction as in Case 1.

5. **Conclusion**:
   Therefore, the smallest \(C_M\) such that the inequality holds for any integers \(a_1, a_2, \ldots, a_{2023}\) is:
   \[
   C_M = 1011 + \frac{1}{M}.
   \]

The final answer is \(\boxed{1011 + \frac{1}{M}}\).