Let $\triangle XOY$ be a right-angled triangle with $\angle XOY=90^\circ$. Let $M$ and $N$ be the midpoints of legs $OX$ and $OY$, respectively. Find the length $XY$ given that $XN=22$ and $YM=31$.

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