defmodule Main do
	def main do
    	[one, zero, _minus, num] = IO.gets("") |> String.trim() |> String.split() |> Enum.map(&String.to_integer/1)
        cond do
            one >= num ->
            	IO.puts(num)
            one + zero >= num ->
            	IO.puts(one)
            true ->
            	num = num - one - zero
                IO.puts(one - num)
        end
    end
end