#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    ll N;
    cin >> N;

    ll ans = 0;
    for ( ll i = 1; i <= N; i++ ) {
        if ( (i % 3 != 0) && (i % 5 != 0) ) {
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}

# include <iostream>
# include <deque>
using namespace std;

string X;
deque<char> dchar;

int main()
{
    cin>>X;

    for (int i=0; i<X.size(); i++)
    {
        dchar.push_back(X[i]);

        if (dchar.size()>=2 && dchar[dchar.size()-2]=='S' && dchar[dchar.size()-1]=='T')
        {
            dchar.pop_back();
            dchar.pop_back();
        }
    }

    cout<<dchar.size()<<endl;
}