Step 1: Define the function and differentiate.
The given function is:
\[
f(x) = x + \frac{1}{x}.
\]
To find critical points, we differentiate \( f(x) \):
\[
f'(x) = 1 - \frac{1}{x^2}.
\]
Step 2: Find the critical points.
Set the derivative equal to zero to solve for critical points:
\[
f'(x) = 0 \quad \Rightarrow \quad 1 - \frac{1}{x^2} = 0 \quad \Rightarrow \quad \frac{1}{x^2} = 1 \quad \Rightarrow \quad x^2 = 1.
\]
This gives two critical points:
\[
x = 1 \quad \text{or} \quad x = -1.
\]
Step 3: Classify the critical points.
To determine the nature of these critical points, we compute the second derivative of \( f(x) \):
\[
f''(x) = \frac{2}{x^3}.
\]
- At \( x = 1 \):
\[
f''(1) = \frac{2}{1^3} = 2 \quad (\text{positive, so } x = 1 \text{ is a local minimum}).
\]
- At \( x = -1 \):
\[
f''(-1) = \frac{2}{(-1)^3} = -2 \quad (\text{negative, so } x = -1 \text{ is a local maximum}).
\]
Step 4: Evaluate the function at the critical points.
- At \( x = 1 \):
\[
f(1) = 1 + \frac{1}{1} = 2 \quad (\text{local minimum } m).
\]
- At \( x = -1 \):
\[
f(-1) = -1 + \frac{1}{-1} = -2 \quad (\text{local maximum } M).
\]
Step 5: Calculate \( M - m \).
Now, calculate the difference between the maximum and minimum values:
\[
M - m = -2 - 2 = -4.
\]
Conclusion:
Thus, the value of \( M - m \) is:
\[
\boxed{-4}.
\]