{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString, putStrLn)
import Prelude hiding (words, getLine, putStrLn, unwords, readLn, print)

import Control.Monad (replicateM)
import Data.List (foldl')
import Data.Maybe (isJust)


class (Read a, Show a) => CPString a where
  cpRead :: String -> a
  cpShow :: a -> ByteString
  cpRead = read
  cpShow = BS.pack . show
instance CPString ByteString where
  cpRead = BS.pack
  cpShow = id
instance CPString String where
  cpRead = id
  cpShow = BS.pack
instance CPString Char where
  cpRead [a] = a
  cpShow = BS.pack . pure
instance CPString Int
instance CPString Integer
instance CPString Float
instance CPString Double
instance CPString Rational
instance CPString a => CPString [a]

readLine :: CPString a => IO [a]
readLine = fmap (cpRead . BS.unpack) . BS.words <$> BS.getLine

printLn :: CPString a => a -> IO ()
printLn = putStrLn . cpShow

main :: IO ()
main = do
  [n] <- readLine @Int
  printLn $ fBSum n

fBSum :: Int -> Int
fBSum n = sum $ map notFB [1..n]

notFB :: Int -> Int
notFB n
  | n `mod` 3 == 0 = 0
  | n `mod` 5 == 0 = 0
  | otherwise = n