#include <bits/stdc++.h>
using namespace std;
template <typename T>
T scan() {
  T x;
  cin >> x;
  return x;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n = scan<int>();
  string s = '*' + scan<string>();
  int m = scan<int>();
  vector<int> dp(n + 1), mn(n + 1);
  vector<vector<int>> a(n + 1, vector<int>(2)), b(n + 1, vector<int>(2));
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 2; ++j) {
      a[i][j] = a[i - 1][j];
      b[i][j] = b[i - 1][j];
    }
    if (s[i] == 'a') a[i][i & 1] += 1;
    if (s[i] == 'b') b[i][i & 1] += 1;
  }
  for (int i = m; i <= n; ++i) {
    dp[i] = dp[i - 1];
    mn[i] = mn[i - 1];
    int aa = (i - m + 1) % 2;
    int bb = 1 - aa;
    if (a[i][1 - aa] - a[i - m][1 - aa] || b[i][1 - bb] - b[i - m][1 - bb])
      continue;
    int op = m - (a[i][aa] - a[i - m][aa]) - (b[i][bb] - b[i - m][bb]);
    if (dp[i - m] + 1 > dp[i]) {
      dp[i] = dp[i - m] + 1;
      mn[i] = op + mn[i - m];
    } else if (dp[i - m] + 1 == dp[i]) {
      mn[i] = min(mn[i], op + mn[i - m]);
    }
  }
  cout << mn[n] << '\n';
}
