#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  string s;
  cin>>s;
  int er=0;
  int ans=s.size();
  rep(i,s.size()){
    if(s[i]=='S') er++;
    if(s[i]=='T' && er!=0){
      er--; ans-=2;
    } 
  }
  cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  long n,sum = 0;
  cin >> n;

  for(long i = 1; i <= n; i++) {
    if(i % 3 == 0 || i % 5 == 0) continue;
    sum += i;
  }

  cout << sum << endl;
}