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}$?

Let's think step by step and output the final answer within \boxed{}.
user