#include <bits/stdc++.h>
using namespace std;
const long long maxN = 100013;
long long n, m;
string s;
long long cnt_a[2][maxN], cnt_b[2][maxN], amount[maxN];
pair<long long, long long> dp[maxN];
vector<long long> last;
long long get_count(long long arr[], long long l, long long r) {
  return arr[l] - arr[r + 1];
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> n >> s >> m;
  for (long long i = n - 1; i >= 0; --i) {
    cnt_a[0][i] = cnt_a[0][i + 1];
    cnt_b[0][i] = cnt_b[0][i + 1];
    cnt_a[1][i] = cnt_a[1][i + 1];
    cnt_b[1][i] = cnt_b[1][i + 1];
    if (s[i] == 'a')
      cnt_a[i & 1][i]++;
    else if (s[i] == 'b')
      cnt_b[i & 1][i]++;
  }
  for (long long i = n - m; i >= 0; --i) {
    long long l = i, r = i + m - 1;
    long long ca[2], cb[2], cq;
    ca[0] = get_count(cnt_a[0], l, r);
    ca[1] = get_count(cnt_a[1], l, r);
    cb[0] = get_count(cnt_b[0], l, r);
    cb[1] = get_count(cnt_b[1], l, r);
    cq = (m - ca[0] - cb[0] - ca[1] - cb[1]);
    if (ca[(i & 1) ^ 1] || cb[i & 1]) cq = -1;
    amount[i] = cq;
  }
  for (long long i = 0; i < n + 5; ++i) {
    dp[i] = make_pair(0, 1e18);
  }
  for (long long i = n - m + 1; i < n + 5; ++i) dp[i].second = 0;
  for (long long i = n - m; i >= 0; --i) {
    dp[i] = dp[i + 1];
    if (amount[i] < 0) continue;
    if ((dp[i + m].first + 1) >= dp[i].first) {
      dp[i].first = (dp[i + m].first + 1);
      dp[i].second = dp[i + m].second + amount[i];
    }
    if (dp[i].first == dp[i + 1].first)
      dp[i].second =
          (((dp[i].second) < (dp[i + 1].second)) ? (dp[i].second)
                                                 : (dp[i + 1].second));
  }
  cout << dp[0].second;
  return 0;
}
