We present a general thermodynamic picture of the folding of RNA-like heteropolymer based on the basic physical principles. The Hamiltonian of the model includes all characteristic interactions explicitly. A particular attention is paid to the electrostatic interactions whose role in the RNA folding is known to be crucial. In this paper we study RNA folding with the full Hamiltonian and describe the spin-glass behavior on the level of tertiary structure. We show that formation of the stable tertiary structure is possible in the random RNA-like molecule. By including into the model the nonspecific interactions of the RNA molecule with counterions, we derive the logarithmic dependencies of the melting and freezing temperatures on the ion concentration, which is consistent with experimental data [R. Shiman and D. E. Draper, J. Mol. Biol. 302, 79 (2000)]. We also infer that the large RNA folds slower than the hierarchical model predicts, which was observed in the experiments.