what is the best way to take missing courses before applying to MS?
I'm not sure that this applies to Russian Universities as my experience stems from the situation in Germany, but I'd recommend talking to the key people at your target University - academic counseling for CS, student representative, dean of students. See what you can find out about the admission process and whether they can give you any pointers.

I myself have a Bachelor in Applied Math and a Master in CS. Before applying for the MS, I visited the University I wanted to get into and met with the faculty member who was responsible for the academic counseling for CS students. I talked him through my undergrad courses and other experience from internships and he encouraged me to apply right away although I technically did not have enough undergrad CS courses according to the admission guidelines. He also gave me a few pointers on how to write the application in such a way that the admission committee would recognize my practical experience. 

His advice: He gave me the list of mandatory undergrad courses and told me that I should match each course with something from my previous studies or my practical experience, to show that even if I had no formal education in some areas, I at least knew the gist of the subject.

I was admitted conditionally and had to complete the two undergrad CS courses in which my prior experience was lacking the most within the first year on top of my regular studies.

In my second year I became the student representative to the admission committee and had a few applicants approach me on the same subject. I gave the same advice, because I noticed early on that the committee would often just hold the list of requirements up to the applicants undergrad transcripts and tick of the boxes.
Even such stupid things as differently named courses could throw the committee off, so I made it my job to go through all the applications and check the matching with the requirements.

In one particular case, a student was very enthusiastic and even ran his own IT-startup business, but the gap between his undergrad studies in a different subject and a CS undergrad was just too big. We had to refuse him the first time he applied. For legal reasons, we couldn't do more than send the standard letter, but luckily he did the smart thing and approached us and between everybody in the admission committee and academic counseling we figured out a way to have him do undergrad courses for a semester and then delay the decision about his follow-up application until the exam results were out and we could make a case for him to be admitted on conditions, like I was.

Your second question, which classes to take, will only be answered when you know what classes they look for in an applicant from another subject. 

The people in the application committee at my university really looked for theoretical background. Do we think this applicant knows what P vs NP is? Do we think he can analyze the runtime of an algorithm? Do we think he knows the difference between a proof and an experiment/example? Percieved knowledge gaps in other subjects like electrical engineering or computer networks or operation systems where often seen as less of a problem if the applicants motivation letter stated that he wanted to specialize in an area where he likely wouldn't need that knowledge.
When in doubt, the committee would often say that the funding depended in part on how successful the students were (i.e. it was better not to admit one than to admit him and have him fail) so they would discuss: Do we think that this applicant will complete his studies in a successful and timely manner?

So one more point of advice, which worked well during my time on the committee: Show in your cover letter that you have a clear idea of what you want to do in your masters, why you want to do it, and why you think you have the necessary background and motivation to be successful at it.