Dear Student,
As given in the question, for first case we can write, using Newton's second law
Force, F1 = m1a1 ......(1)
And for second case, F2 = m2a2 .........(2)
Now, According to the question, F1 = F2
So from (1) & (2) we get,
m1a1 = m2a2 [ Required relation]
Regards