6. Divide a rectangle with side lengths of positive integers $m, n$ into several squares with side lengths of positive integers, with each square's sides parallel to the corresponding sides of the rectangle. Try to find the minimum value of the sum of the side lengths of these squares.
6. Let the required minimum value be $f(m, n)$, it can be proven that $f(m, n)=m+n-(m, n)$,
(*)
where $(m, n)$ denotes the greatest common divisor of $m$ and $n$.
In fact, without loss of generality, assume $m \geqslant n$.
(1) By induction on $m$, it can be proven that there exists a valid partition such that the sum of the side lengths of the resulting squares is exactly $m+n-(m, n)$. When $m=1$, the proposition is clearly true.
Assume that the conclusion holds for $m \leqslant k (k \geqslant 1)$.
When $m=k+1$, if $n=k+1$, then the proposition is clearly true;
if $nm+n-(m, n)$.

If $a_{1}=n$, then a rectangle with side lengths $m-n$ and $n$ can be divided into squares with side lengths $a_{2}, \cdots, a_{p}$ as required by the problem. By the induction hypothesis, $a_{2}+\cdots+a_{p} \geqslant(m-n)+n-(m-n, n)=m-(m, n)$.
Thus, $a_{1}+a_{2}+\cdots+a_{p} \geqslant m+n-(m, n)$,
Therefore, when $m=k+1$, $f(m, n) \geqslant m+n-(m, n)$.
Furthermore, by (1), we know that $f(m, n)=m+n-(m, n)$.