sum1 <- function(m) { res = 0 for(i in 1:dim(m)[1]) { for(j in 1:dim(m)[2]) { res <- res + m[i,j] } } return(res) }