The valuation of a company is complicated in general; here though, additional to fair market value, the investment- and intrinsic value are to be determined as well.
After the valuation is complete, the parties will agree upon the swap ratio; this will determine the number of shares that each shareholder will receive.
In South Korea, the merger ratio is defined by a certain formula according to the law, if both companies are listed on the KRX.
Sometimes, a part of the agreement will not allow the new shareholders to sell for a certain time period to avoid a sudden drop in share price.
This is a form of a shareholder rights plan or poison pill strategy that is used to combat hostile takeovers.