#include <bits/stdc++.h>
using namespace std;
void read(int &first) {
  first = 0;
  int f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    first = (first << 1) + (first << 3) + c - '0';
    c = getchar();
  }
  first *= f;
  return;
}
int fs(int first) { return first < 0 ? -first : first; }
void print(int first) {
  if (first < 10) {
    putchar(first + '0');
    return;
  }
  print(first / 10);
  putchar(first % 10 + '0');
  return;
}
void write(int first) {
  if (first < 0) {
    putchar('-');
    first = fs(first);
  }
  print(first);
  return;
}
int mint(int first, int second) { return first < second ? first : second; }
int maxt(int first, int second) { return first > second ? first : second; }
int n, l[5005], s[5005], r[5005], cnt, p, m;
void pre(int d) {
  char c = getchar();
  while (c == '?' || c == ')') c = getchar();
  if (c == '(') {
    l[d] = ++cnt;
    pre(cnt);
    r[d] = ++cnt;
    pre(cnt);
  } else {
    int first = 0;
    while (c >= '0' && c <= '9') {
      first = (first << 1) + (first << 3) + c - '0';
      c = getchar();
    }
    s[d] = first;
  }
}
int dp1[5005][105], dp2[5005][5005];
void dfs(int u) {
  for (int i = 0; i <= p; i++) dp1[u][i] = -0x3f3f3f3f;
  for (int i = 0; i <= p; i++) dp2[u][i] = 0x3f3f3f3f;
  if (l[u] == r[u]) {
    dp1[u][0] = s[u];
    dp2[u][0] = s[u];
    return;
  }
  dfs(l[u]);
  dfs(r[u]);
  dp1[u][0] = dp1[l[u]][0] - dp2[r[u]][0];
  dp2[u][0] = dp2[l[u]][0] - dp1[r[u]][0];
  for (int i = 1; i <= p; i++) {
    int k = i - 1;
    for (int j = 0; j <= i; j++)
      dp1[u][i] = maxt(dp1[u][i], dp1[l[u]][j] - dp2[r[u]][i - j]);
    for (int j = 0; j <= i; j++)
      dp2[u][i] = mint(dp2[u][i], dp2[l[u]][j] - dp1[r[u]][i - j]);
    for (int j = 0; j <= k; j++)
      dp1[u][i] = maxt(dp1[u][i], dp1[l[u]][j] + dp1[r[u]][k - j]);
    for (int j = 0; j <= k; j++)
      dp2[u][i] = mint(dp2[u][i], dp2[l[u]][j] + dp2[r[u]][k - j]);
  }
}
void dfs1(int u) {
  for (int i = 0; i <= m; i++) dp1[u][i] = -0x3f3f3f3f;
  for (int i = 0; i <= m; i++) dp2[u][i] = 0x3f3f3f3f;
  if (l[u] == r[u]) {
    dp1[u][0] = s[u];
    dp2[u][0] = s[u];
    return;
  }
  dfs1(l[u]);
  dfs1(r[u]);
  dp1[u][0] = dp1[l[u]][0] + dp1[r[u]][0];
  dp2[u][0] = dp2[l[u]][0] + dp2[r[u]][0];
  for (int i = 1; i <= m; i++) {
    int k = i - 1;
    for (int j = 0; j <= k; j++)
      dp1[u][i] = maxt(dp1[u][i], dp1[l[u]][j] - dp2[r[u]][k - j]);
    for (int j = 0; j <= k; j++)
      dp2[u][i] = mint(dp2[u][i], dp2[l[u]][j] - dp1[r[u]][k - j]);
    for (int j = 0; j <= i; j++)
      dp1[u][i] = maxt(dp1[u][i], dp1[l[u]][j] + dp1[r[u]][i - j]);
    for (int j = 0; j <= i; j++)
      dp2[u][i] = mint(dp2[u][i], dp2[l[u]][j] + dp2[r[u]][i - j]);
  }
}
int main() {
  pre(0);
  read(p), read(m);
  if (p < m)
    dfs(0);
  else
    dfs1(0);
  if (p < m)
    printf("%d", dp1[0][p]);
  else
    printf("%d", dp1[0][m]);
}
