Ascending: shift slightly forward (toward the fall board) when crossing over from a white key to a black key.
Descending: shift slightly backward (away from the fall board) when crossing under from a black key to a white key.
An example executing the first notes.
1. The hand starts out here.

2. Now finger 3 must cross finger 4.
2A. The painful way.
Attempting to move the hand in a directly lateral motion requires the most extreme crossover of the 4th over the 3rd finger. The problem is that finger 3 is blocked by the near edge of the B to its right.

2B. The comfy way.
Shift the hand very slightly forward and toward black key, leaving finger 3 in place by allowing it to curl a bit. This gives the clearance needed and, with a tiny rotation of the hand, brings finger 3 easily to its destination.1

3. All the rest of the notes
This strategy will work with 3 over 4, 3 over 5, and 4 over 5 when ascending. When descending, reverse the process, crossing the relevant finger under its neighbor: so 5 under 4, 5 under 3, and 4 under 3.
1As a general rule, twisting motions should be avoided. In this case, however, it is a very small movement, and necessary.