Let $M$ be a $n-$dimensional smooth manifold and $X\in\chi(M)$ be a smooth vector field defined on it. Let $f_1,...,f_{n-2}:M\rightarrow \mathbb{R}$ be functionally independent first integrals of $X$, i.e. $$ L_{X}f_i=0,\quad \forall i=1,2,...,n-2. $$
Moreover, suppose there exists another vector field $Y\in\chi(M)$, independent from $X$, which is commuting with it, namely $$ \mathcal{L}_X Y = [X,Y]=0. $$
Is there some known general condition that $Y$ must satisfy in order to share the first integrals with $X$?
I tried saying that for any $i=1,...,n-2$ since $XY=YX$, then we have $$ 0=YX(f_i) = XY(f_i) $$ and hence the functions $g_i=Y(f_i)\in\mathcal{C}^{\infty}(M)$ are first integrals of $X$. Namely, when is it true that then $\mathcal{L}_{Y}f_i=0$ for all the $i'$s?
But at this point, I am stuck because I can't think about some reasonable condition on $Y$ in order to be sure that $Y(f_i)=0$.
My ideas are to use the fact that we can have at most $(n-1)$ independent first integrals of both $X$ and $Y$, and moreover at most $n$ linearly independent vectors on $T_mM$ for any $m\in M$, but I don't actually know how to proceed.