I'll add another approach. It only works if $\mathbb{F}$ has characteristic $0$ and admittedly it is probably rooted in the same idea as above, but I think it's pretty cute, and at least in some sense conceptually pretty easy.
One can prove that on $M_n(\mathbb{F})$ there is essentially only one trace. That is, if $t, \tau: M_n(\mathbb{F})\to \mathbb{F}$ are linear maps which satisfy $\tau(xy)=\tau(yx)$ and $t(xy)=t(yx)$ for all $x,y$ then $t$ and $\tau$ differ by a constant.
Say then $T_m$ and $T_n$ are the traces on $M_m(\mathbb{F})$ and $M_n(\mathbb{F}).$ Now, using $f$ you can pull back the trace on $M_m$ to a trace on $M_n$. That is, if you consider $\tau(x)=T_m(f(x))$ for $x\in M_n$ you will notice this is linear and has the 'trace' condition $\tau(xy)=\tau(yx)$ for all $x,y.$
It's just that $\tau(1_n)=m$ not $n$ but this is no big deal. If we rescale, we find that $\frac{n}{m}T_m(f(x))$ must be equal to $T_n(x)$ for all $x\in M_n.$
In other words, for all $x\in M_n$ we have $\frac{m}{n}T_n(x)=T_m(f(x)).$ In particular, if $x=e_{11}$ then $\frac{m}{n}=T_m(f(e_{11}).$
Nevertheless. $f(e_{11})\in M_n$ is still an idempotent matrix - so all its eigenvalues are either $0$ or $1$ and in particular, the trace, being the sum of the eigenvalue, must be an integer.
Edit: let me add another remark - I could try and sell this as yet a third solution, but it's really just a rephrasing of Alex's solution above. The point is it uses a more general framework, so on the one hand I think it puts things into perspective really nicely, while on the other hand maybe someone find all this abstract nonsense intersting (you can tell I'm quite fond of this question haha).
Anyway, there is this equivalence relation for rings, called Morita equivalence, which is weaker than isomorphism, but still captures a lot of interesting properties of the rings.
One says two (unital) rings $R$ and $S$ are Morita equivalent if the category of left (right) $R$-modules is equivalent to the category of left (right) $S$-modules. What this means, is for every left $R$-module $M$ one may associate in a nice way (i.e. compatible with module homomorphisms) an $S$-module $\mathcal{F}(M)$, and to any $S$ module $N$ an $R$ module $\mathcal{G}(N)$ in such a way that $M\simeq \mathcal{G}(\mathcal{F}(M))$ as $R$ modules and also $\mathcal{F}(\mathcal{G}(N))\simeq N$ as $S$ modules (for every $R$ module $M$ and every $S$ module $N$).
It is a fact that whenever $R$ is a unital ring, $R$ and $M_n(R)$ are Morita equivalent for every positive integer $n$. The point, however, is that the functors $\mathcal{F}$ and $\mathcal{G}$ are very explicit.
Namely, for every $R$ module $M$ one defines $\mathcal{F}(M)$ to be the direct sum of $n$ copies of $M$, where $M_n(R)$ acts on $\bigoplus_{i=1}^nM$ by 'matrix multiplication' -that is, a matrix $x=(r_{ij})_{1\leq i,j\leq n}$ acts on an element $m=(m_i)_{1\leq i\leq n}$ by $x.m=(\sum_jr_{ij}m_j)_i.$
Converesely, for every $M_n(R)$ module $N$ one simply defines an $R$ module by $\mathcal{G}(N)=e_{11}N$ where an element $r\in R$ acts on an element $e_{11}n$ simply by $r.e_{11}n=(re_{ii})n.$
One can prove these $\mathcal{F}$ and $\mathcal{G}$ have the desired properties. In particular, what this shows is that for every $M_n(R)$ module $M$ there is an $R$ module $N$ such that $M\simeq \bigoplus_{i=1}^{n}N$ as $M_n(R)$ modules, where the action on the RHS is as defines above.
How this is useful for the given problem: $\mathbb{F}^m$ is an $M_m(\mathbb{F})$ module in the obvious way. By restricting scalars along the morphism $f$ we can make $\mathbb{F}^m$ into a module over $M_n(\mathbb{F})$ - i.e. we define an action of $M_n(\mathbb{F})$ on $\mathbb{F}^m$ by $x.v=f(x)v$ for every $x \in M_n(\mathbb{F})$ and $v\in \mathbb{F}^m$.
Using the above result, there is an $\mathbb{F}$ module N, i.e. a vector space over $\mathbb{F}$ such that $\mathbb{F}^m\simeq \bigoplus_{i=1}^nN.$ Now if this holds at the level of $M_n(\mathbb{F})$ modules, it also holds at the level of vector spaces over $\mathbb{F}$, so simply looking at dimensions now gives $m=n\text{dim}(N)$, and of course $\text{dim}(N)$ is an integer.
The salient general result is that if $R$ is a (possibly noncommutative) ring, $M$ is an $R$-module, and $\text{n}$ is a natural number, then homomorphisms $\text{End}{R^{\text{n}}}\to\text{End}\left(M\right)$ are in bijection with decompositions of $M$ as $\text{n}$-fold (self-)biproducts (i.e., expressions $M\simeq\left(M'\right)^{\oplus\text{n}}$).
– Rafi Feb 22 '25 at 03:00