#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 9;
char vec[MAX_N];
int res[MAX_N];
int s[2][MAX_N];
int dp[MAX_N];
int cost[MAX_N];
int main() {
  int N, M, T;
  memset(res, 0, sizeof(res));
  scanf("%d%s%d", &N, vec + 1, &M);
  for (int i = 1; i <= N; i++) {
    res[i] = res[i - 1] + (vec[i] == '?');
    if (vec[i] != 'a') s[0][i] = s[1][i - 1] + 1;
    if (vec[i] != 'b') s[1][i] = s[0][i - 1] + 1;
    if (s[M & 1][i] >= M) {
      dp[i] = dp[i - M] + 1;
      cost[i] = cost[i - M] + res[i] - res[i - M];
    } else {
      dp[i] = dp[i - 1];
      cost[i] = cost[i - 1];
    }
    if (dp[i] <= dp[i - 1]) {
      if (dp[i] == dp[i - 1])
        cost[i] = min(cost[i], cost[i - 1]);
      else
        cost[i] = cost[i - 1];
    }
  }
  cout << cost[N] << endl;
  return 0;
}
