Castelnuovo-Mumford regularity and cohomological dimension