A, B, S = gets.split.map(&:to_i) ans = if (A - S).abs <= (B - S).abs or S == 1 (A - S).abs + S elsif A < S (B - S).abs + (S - A).abs + A else (B - S).abs + S - 1 + A end puts ans