PUMaC 2017 Number Theory B Problem 3

Shaq sees the numbers 1 through 2017 written on a chalkboard. He repeatedly chooses three numbers, erases them, and writes one plus their median. (For instance, if he erased -2, -1, 0 he would replace them with 0.) If M is the maximum possible final value remaining on the board, and if m is the minimum, compute M - m.