#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  string s;
  cin >> n >> k >> s;
  vector<int> v;
  long long depth = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') {
      depth++;
      v.push_back(depth);
      if (s[i + 1] == ')') {
        continue;
      }
      v.push_back(depth);
    } else if (s[i] == ')') {
      depth--;
      if (depth > 0 && s[i + 1] == '(') v.push_back(depth);
    }
  }
  sort(v.begin(), v.end(), greater<int>());
  long long result = 0;
  for (int i = 0; i < k; i++) {
    result += v[i];
  }
  cout << result << "\n";
}
