#include <bits/stdc++.h>
struct State {
  int v;
  int k;
  int x;
  bool is_v_last;
  State(const int v, const int k, const int x, const bool is_v_last)
      : v(v), k(k), x(x), is_v_last(is_v_last) {}
  bool operator==(const State& other) const {
    return v == other.v && k == other.k && x == other.x &&
           is_v_last == other.is_v_last;
  }
};
struct MyStateHash {
  const size_t operator()(const State& other) const {
    return std::hash<int>()(other.v) ^ std::hash<int>()(other.k) ^
           std::hash<int>()(other.x) ^ std::hash<bool>()(other.is_v_last);
  }
};
struct Counts {
  int v;
  int k;
  int x;
  Counts(const int v, const int k, const int x) : v(v), k(k), x(x) {}
};
size_t get_id(const int v, const int k, const int x, bool is_v_last,
              const int string_size) {
  return 2 * string_size * string_size * v + 2 * string_size * k + 2 * x +
         (is_v_last ? 1 : 0);
}
void update_score(std::vector<int>& state_score, const size_t state,
                  const size_t base_state, const int new_value) {
  if (state_score[base_state] != -1) {
    int old_state_value = state_score[base_state];
    if (state_score[state] == -1 ||
        state_score[state] > new_value + old_state_value) {
      state_score[state] = new_value + old_state_value;
    }
  }
}
int main() {
  int string_size;
  std::cin >> string_size;
  std::vector<Counts> counts;
  std::vector<int> v_indices;
  std::vector<int> k_indices;
  std::vector<int> x_indices;
  Counts cur_counts(0, 0, 0);
  for (size_t i = 0; i < string_size; ++i) {
    char letter;
    std::cin >> letter;
    if (letter == 'K') {
      ++cur_counts.k;
      k_indices.push_back(i);
    } else if (letter == 'V') {
      ++cur_counts.v;
      v_indices.push_back(i);
    } else {
      ++cur_counts.x;
      x_indices.push_back(i);
    }
    counts.push_back(cur_counts);
  }
  std::vector<int> state_score(string_size * string_size * string_size * 3, -1);
  state_score[0] = 0;
  state_score[1] = 0;
  for (int n = 0; n <= string_size; ++n) {
    for (int k = 0; k <= std::min(n, cur_counts.k); ++k) {
      for (int v = 0; v <= std::min(n - k, cur_counts.v); ++v) {
        for (int x = 0; x <= std::min(n - k - v, cur_counts.x); ++x) {
          if (k > 0) {
            int index = k_indices[k - 1];
            Counts count = counts[index];
            update_score(state_score, get_id(v, k, x, false, string_size),
                         get_id(v, k - 1, x, false, string_size),
                         (index - v - k - x + 1 + std::max(0, v - count.v) +
                          std::max(0, x - count.x)));
          }
          if (v > 0) {
            int index = v_indices[v - 1];
            Counts count = counts[index];
            update_score(state_score, get_id(v, k, x, true, string_size),
                         get_id(v - 1, k, x, false, string_size),
                         (index - v - k - x + 1 + std::max(0, k - count.k) +
                          std::max(0, x - count.x)));
            update_score(state_score, get_id(v, k, x, true, string_size),
                         get_id(v - 1, k, x, true, string_size),
                         (index - v - k - x + 1 + std::max(0, k - count.k) +
                          std::max(0, x - count.x)));
          }
          if (x > 0) {
            int index = x_indices[x - 1];
            Counts count = counts[index];
            update_score(state_score, get_id(v, k, x, false, string_size),
                         get_id(v, k, x - 1, false, string_size),
                         (index - v - k - x + 1 + std::max(0, k - count.k) +
                          std::max(0, v - count.v)));
            update_score(state_score, get_id(v, k, x, false, string_size),
                         get_id(v, k, x - 1, true, string_size),
                         (index - v - k - x + 1 + std::max(0, k - count.k) +
                          std::max(0, v - count.v)));
          }
        }
      }
    }
  }
  int result = -1;
  for (int is_v_last = 0; is_v_last < 2; ++is_v_last) {
    long long int id = get_id(cur_counts.v, cur_counts.k, cur_counts.x,
                              is_v_last, string_size);
    if (state_score[id] != -1) {
      if (result == -1 || result > state_score[id]) {
        result = state_score[id];
      }
    }
  }
  std::cout << result << std::endl;
  return 0;
}
