#include<bits/stdc++.h>

using namespace std;
#define int long long
string s;
int n;
const int N = 307;
int mem[N][N];
int k;

int dp(int i, int o) {
  if (i >= n)return o;
  int &res = mem[i][o];
  if (~res)return res;
  res = 1e9;
  if (s[i] == 'f' && o > 0) {
    for (int j = i + 1, c = 0; c <= k && j <= n; ++j, ++c)
      res = min(res, dp(j, o - 1));
  }
  if (s[i] == 'o') {
    res = min(res, dp(i + 1, o + 1));
  }
  res = min(res, o + 1 + dp(i + 1, 0));
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> s >> k;
  n = s.length();
  memset(mem, -1, sizeof mem);
  cout << dp(0, 0);
}