import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Maybe (fromJust)
import Debug.Trace

solve :: Int -> Int -> Int
solve 0 time = time
solve x time
    | x < time = -1
    | (x - time) == 0 = time
    | (x - time) >= next = solve (x - time) next
    | otherwise = solve x next
    where
        next = time + 1

main :: IO ()
main = do
    x <- (fst . fromJust . BS.readInt) <$> BS.getLine
    print $ solve x 1