K1i + K2i = K1f + K2f
or
(1/2)*m1*v1i^2 + (1/2)*m2*v2i^2 = (1/2) *m1*v1f^2
+ (1/2)*m2* v2f^2
where "i" is used on initial values and "f" is used on final values.
Note that while the law of conservation of momentum applies to every collision, the further principle of conservation of kinetic energy for elastic collisions may only be applied if you know the collision can be treated as elastic. In other collisions, a significant fraction of the kinetic energy may be converted into other forms of energy, such as thermal energy, so is not conserved.