minzip [] bs = bs
minzip as [] = as
minzip (a:as) (b:bs)
  | a < b = a:minzip as (b:bs)
  | otherwise = b:minzip (a:as) bs

main = do
  k <- read . last . words <$> getLine :: IO Int
  a <- map read . words <$> getLine :: IO [Int]
  b <- map read . words <$> getLine :: IO [Int]
  print . length . takeWhile (<=k) . scanl1 (+) $ minzip a b