A theorem on products of matrices