Although correct, using the concept of F = (M-m)g is a very unorthodox way to explain acceleration in a simple Atwood machine, so I am compelled to explain I hope more clearly.
To solve for the acceleration of each mass, you must first realize that the masses M and m will have the same magnitude of acceleration, since they are connected together by a cord and must therefore move and accelerate ,"a", at the same rate (the heavy one accelerates and moves down, while the lighter one accelerates and moves up). You must also realize that the pulley is assumed massless and frictionless, a so called ideal pulley, in which case the tension in the cord on each side of the pulley, acting up on each mass, is the same, "T".
Now we employ the use of Free Body Diagrams, often abbreviated as FBD, one of the most powerful tools in Intro Physics Mechanics (Statics and Dynamics). The FBD concept should be mastered. In a FBD, each part of the system is 'isolated', and the forces acting on that isolated part, known and unknown, are identified and shown in a sketch, and then Newton's laws are applied.
For this problem, first isolate the large mass, M, in a FBD. Its weight, Mg, acts down, and the tension force in the cord, T, acts up. The net force acting on the mass M is thus Mg - T, acting down, in the direction of its acceleration. We now write Newton's 2nd law
F_net = Ma, or
Mg - T = Ma (equation 1)
Now isolate the lighter mass, m, and draw the FBD: its weight, mg acts down, and the tension force in the cord, T, acts up. The net force acting on mass m is thus T - mg, acting up, in the direction of its acceleration. again using Newton 2,
F_net = ma, or
T - mg = ma (equation 2)
You now have 2 simultaneous equations with 2 unknowns, T and a. You should be able to solve these now by adding the 2 equations together, which eliminates T, and yields the result Mg - mg = Ma + ma, or
(M - m)g = (M + m)a, from which
a = (M - m)g/(M + m)
Do not memorize this equation. Instead, master the art of drawing good FBD's! I seldom get into this detail when responding, but it is imperative to understand this concept.
And we welcome you to PF!