#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);
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgaW50IGxvbmcgbG9uZwpzdHJpbmcgczsKaW50IG47CmNvbnN0IGludCBOID0gMzA3OwppbnQgbWVtW05dW05dOwppbnQgazsKCmludCBkcChpbnQgaSwgaW50IG8pIHsKICBpZiAoaSA+PSBuKXJldHVybiBvOwogIGludCAmcmVzID0gbWVtW2ldW29dOwogIGlmICh+cmVzKXJldHVybiByZXM7CiAgcmVzID0gMWU5OwogIGlmIChzW2ldID09ICdmJyAmJiBvID4gMCkgewogICAgZm9yIChpbnQgaiA9IGkgKyAxLCBjID0gMDsgYyA8PSBrICYmIGogPD0gbjsgKytqLCArK2MpCiAgICAgIHJlcyA9IG1pbihyZXMsIGRwKGosIG8gLSAxKSk7CiAgfQogIGlmIChzW2ldID09ICdvJykgewogICAgcmVzID0gbWluKHJlcywgZHAoaSArIDEsIG8gKyAxKSk7CiAgfQogIHJlcyA9IG1pbihyZXMsIG8gKyAxICsgZHAoaSArIDEsIDApKTsKICByZXR1cm4gcmVzOwp9CgppbnQzMl90IG1haW4oKSB7CiAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgY2luLnRpZShudWxscHRyKTsKICBjaW4gPj4gcyA+PiBrOwogIG4gPSBzLmxlbmd0aCgpOwogIG1lbXNldChtZW0sIC0xLCBzaXplb2YgbWVtKTsKICBjb3V0IDw8IGRwKDAsIDApOwp9