You could look at it an different way, transform the wall of bricks to a wall of edges, in your example it would be
1, 3, 5
3, 4
1, 4
2
3, 4
1, 4, 5
if you look at the middle column you are crossing the 4th edge, that is the edge after a total width of 4 three times more than any other.
height minus maximum edges that can be crossed in a column is your answer.