module Main where

import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Control.Monad
import Data.List

main :: IO ()
main = do
    [a,b,c,k] <- map (fst.fromJust.BS.readInt).BS.words <$> BS.getLine
    let ass = [ (one,zero,minus) | one <- [0..a] , zero <- [0..b], minus <-[0..c], (one+zero+minus) == k ]
    putStr $ show $ maximum (map ( \ (one,zero,minus) -> one-minus) ass)
    