#include <bits/stdc++.h>
using namespace std;
int n, t, d[1000005][2][2];
string temp = "ab";
pair<int, int> dp[1000005];
char s[1000005];
bool check(int l, int r) {
  if (s[l] == 'b') return 0;
  int temp = l & 1;
  if (d[r][temp][1] - d[l - 1][temp][1] != 0) return 0;
  temp = !temp;
  if (d[r][temp][0] - d[l - 1][temp][0] != 0) return 0;
  return 1;
}
int calc(int l, int r) {
  int len = r - l + 1;
  for (int i = (0); i <= (1); ++i)
    for (int j = (0); j <= (1); ++j) len -= (d[r][i][j] - d[l - 1][i][j]);
  return len;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n;
  for (int i = (1); i <= (n); ++i) cin >> s[i];
  cin >> t;
  for (int i = (1); i <= (n); ++i) {
    for (int j = (0); j <= (1); ++j)
      for (int k = (0); k <= (1); ++k) d[i][j][k] = d[i - 1][j][k];
    if (s[i] != '?') ++d[i][i & 1][temp.find(s[i])];
  }
  for (int r = (t); r <= (n); ++r) {
    int l = r - t + 1;
    dp[r] = dp[r - 1];
    if (check(l, r)) {
      if (dp[r].first < dp[l - 1].first + 1) {
        dp[r].first = dp[l - 1].first + 1;
        dp[r].second = calc(l, r) + dp[l - 1].second;
      } else if (dp[r].first == dp[l - 1].first + 1)
        dp[r].second = min(dp[r].second, dp[l - 1].second + calc(l, r));
    }
  }
  cout << dp[n].second;
  return 0;
}
