A treasure chest contains 23 emeralds and 30 diamonds. Unfortunately, 39 of the stones are fake and had to be removed. The number of real stones left (y) is multiplied by itself and then 37 is subtracted to get a number (g) that represents the value of the chest. 

In another chest, there were 540 rubies which have been equally shared amongst 45 pirates, and then 3 are lost in the division. The remaining number (x) is subtracted from the value of the first chest (g) to get a new value.

In the same chest as the rubies, there were also 23 pearls and 11 zirconias, but 9 pieces had to be discarded due to damage. The count (s) is subtracted from the new value to determine the value (m) of the remaining treasure.

What is the value (m) of the remaining treasure?