Align Surfaces of two Cubes

I want to align 2 cubes to each other even though they look in two different directions.
The snap is not a problem. But I can’t manage the alignment as in the result. The left cube looks to the right and the right cube looks up. My English is not the best, I hope you understand the problem.