Let $M=\{0,1,2,\dots,2022\}$ and let $f:M\times M\to M$ such that for any $a,b\in M$,
\[f(a,f(b,a))=b\]
and $f(x,x)\neq x$ for each $x\in M$. How many possible functions $f$ are there $\pmod{1000}$?
1. Given the set \( M = \{0, 1, 2, \dots, 2022\} \) and the function \( f: M \times M \to M \) such that for any \( a, b \in M \),
   \[
   f(a, f(b, a)) = b
   \]
   and \( f(x, x) \neq x \) for each \( x \in M \).

2. Denote \( c = f(a, a) \). By substituting \( a = b \) in the given functional equation, we get:
   \[
   f(a, f(a, a)) = f(a, c) = a
   \]
   This implies that \( f(a, c) = a \).

3. Now, consider the expression \( f(c, f(a, c)) \). Since \( f(a, c) = a \), we have:
   \[
   f(c, f(a, c)) = f(c, a) = a
   \]

4. Next, we use the original functional equation again with \( a \) and \( f(c, a) \):
   \[
   f(a, f(c, a)) = f(a, a) = c
   \]
   However, we know that \( f(a, a) = c \), and by the problem's condition, \( f(x, x) \neq x \) for each \( x \in M \). This implies that \( c \neq a \).

5. We have derived that \( f(a, c) = a \) and \( f(c, a) = a \). This leads to a contradiction because if \( f(a, c) = a \) and \( f(c, a) = a \), then \( f(a, a) = c \) and \( f(c, c) = a \), which violates the condition \( f(x, x) \neq x \).

6. Therefore, no such function \( f \) can exist that satisfies both conditions simultaneously.

\(\blacksquare\)

The final answer is \( \boxed{0} \)