--- Copyright © 2008 Bart Massey
--- ALL RIGHTS RESERVED
--- [This program is licensed under the "3-clause ('new') BSD License"]
--- Please see the file COPYING in the source
--- distribution of this software for license terms.

import System.Environment
import Data.RLE

unrle_data :: Int -> [(Int, Int)]
unrle_data n = [(k, k) | k <- [1..n]]

main = do
  [arg] <- getArgs
  let a = read arg
  -- a = n * (n + 1) / 2
  -- so solve 0 = n * n + n - 2 * a for n
  -- rounding up, then take only a elements
  let n = ceiling ((sqrt(1 + 8 * fromIntegral a) - 1) / 2)
  (putStrLn . show . length . take a . unrle . unrle_data) n
