I think this does what you're looking for:
M <- matrix(c(4, 2, 2, 5, 3, 2), ncol = 3)
M2 <- cbind(M, matrix(0, nrow=nrow(M), ncol=nrow(M) - 1))
vec <- seq(len=ncol(M2))
M2.ord <- M2
for(i in 1:nrow(M2)) {
M2.ord[i, ] <- vec
vec <- c(tail(vec, 1), head(vec, -1)) + ncol(M2)
}
M2.shift <- matrix(t(M2)[M2.ord], nrow=nrow(M2))
sum(do.call(pmax, split(M2.shift, row(M2.shift))))
The annoying step is creating M2.shift:
[,1] [,2] [,3] [,4]
[1,] 4 2 3 0
[2,] 0 2 5 2
From that point forward, it's pretty much the logic you used. Note that this assumes we use all steps defined in M.