#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int dp[N], g[N], h[2][N];
char a[N];
int n, m;
int pre[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  dp[0] = 0, g[0] = 0, pre[0] = 0;
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + (a[i] == '?');
    if (a[i] != 'a') h[0][i] = h[1][i - 1] + 1;
    if (a[i] != 'b') h[1][i] = h[0][i - 1] + 1;
    dp[i] = dp[i - 1], g[i] = g[i - 1];
    if (h[m & 1][i] >= m) {
      if (dp[i] < dp[i - m] + 1)
        dp[i] = dp[i - m] + 1, g[i] = g[i - m] + (pre[i] - pre[i - m]);
      if (dp[i] == dp[i - m] + 1)
        g[i] = min(g[i - m] + pre[i] - pre[i - m], g[i]);
    }
  }
  cout << g[n];
  return 0;
}
