Cyclical monotonicity and the ergodic theorem