Consider the following image, representing the situation
There is a rather easy method to solve this, but one must make a very simple assumption, that the two blocks move together under this acceleration, ie they have the same acceleration
Under this assumption, the two blocks can be considered one composite( this is only true under the above assumption). Applying newtons second law on the composite system
But the only force on the
Note: one could have as well solved the problem by drawing free body diagrams for both the blocks, but that would be rather messy, taking advantage of one assumption, makes the problem much easier.