#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
string command;
int n, k, dp[102][52][205][2];
int func(int indx, int operation, int pos, int turn) {
  if (indx == n) {
    if (operation == k) {
      if (pos <= 100) return pos;
      return pos - 100;
    } else
      return -1e5;
  }
  if (dp[indx][operation][pos][turn] != -1) {
    return dp[indx][operation][pos][turn];
  }
  int ans = -1e5, curPos = pos;
  if (turn == 0) {
    if (curPos == 101)
      curPos = 0;
    else if (curPos > 101)
      curPos--;
    else
      curPos++;
  } else {
    if (curPos == 0)
      curPos = 101;
    else if (curPos <= 100)
      curPos--;
    else
      curPos++;
  }
  if (command[indx] == 'T') {
    ans = max(ans, func(indx + 1, operation, pos, 1 - turn));
    for (int i = 2;; i += 2) {
      if (operation + i > k) break;
      ans = max(ans, func(indx + 1, operation + i, pos, 1 - turn));
    }
    if (operation + 1 <= k) {
      ans = max(ans, func(indx + 1, operation + 1, curPos, turn));
    }
  } else {
    ans = max(ans, func(indx + 1, operation, curPos, turn));
    for (int i = 2;; i += 2) {
      if (operation + i > k) break;
      ans = max(ans, func(indx + 1, operation + i, curPos, turn));
    }
    if (operation + 1 <= k) {
      ans = max(ans, func(indx + 1, operation + 1, pos, 1 - turn));
    }
  }
  return dp[indx][operation][pos][turn] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j;
  cin >> command >> k;
  n = (int)command.size();
  memset(dp, -1, sizeof dp);
  int ans = func(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}
