defmodule Main do def solve(l, l, _) do 1 end def solve(l, r, m) when (r - l) >= m do m end def solve(l, r, m) do a = rem(l, m) b = rem(r, m) cond do b >= a -> (b - a + 1) true -> (m - a) + b + 1 end end def main do [l, r, m] = IO.gets("") |> String.trim |> String.split |> Enum.map(&String.to_integer/1) solve(l, r, m) |> IO.puts end end