A computing method for calculation of total similarity of two amino acid sequences depending on the number of gaps introduced into these sequences has been developed. It was based on Needleman--Wunsch--Sankoff's principles. The application of the method to randomized sequences enables us to select the optimal alignment of real sequences, in which the number of gaps is statistically justified. In this paper an example of the application of this approach is described and the statistically optimal alignment of somatotropin and prolactin amino acid sequences with two gaps is suggested.