module Main where

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

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

solve :: Int -> [Int] -> [Int] -> [Int] -> Int
solve k s [] [] = length s
solve k s [x] [] = if sum s + x <= k then length s + 1 else length s
solve k s [] [y] = if sum s + y <= k then length s + 1 else length s
solve k s (x:xs) [] = if sum s + x <= k then solve k (x:s) [] xs else length s
solve k s [] (y:ys) = if sum s + y <= k then solve k (y:s) [] ys else length s
solve k s (x:xs) (y:ys)
  | x <= y && sum s + x <= k = solve k (x:s) xs (y:ys)
  | x > y && sum s + y <= k = solve k (y:s) (x:xs) ys
  | otherwise  = length s

main = do
  [[_,_,k], a, b] <- getIntNList 3
  print $ solve k 0 a b