#include <bits/stdc++.h>
using namespace std;
const int N = 2e4;
const int INF = 1e8;
int n, P, M;
int rt, son[N][2], size[N], val[N];
int dp_max[N][210], dp_min[N][210];
char s[N];
void process() {
  rt = 0;
  n = strlen(s);
  stack<int> st;
  for (int i = 0; i < n; i++) {
    if (s[i] == ')') {
      ++rt;
      son[rt][1] = st.top();
      st.pop();
      son[rt][0] = st.top();
      st.pop();
      st.push(rt);
      size[rt] = size[son[rt][0]] + size[son[rt][1]] + 1;
    } else if ('1' <= s[i] && s[i] <= '9') {
      ++rt;
      val[rt] = s[i] - '0';
      st.push(rt);
    }
  }
}
void dfs(int u) {
  if (val[u]) {
    dp_max[u][0] = dp_min[u][0] = val[u];
    return;
  }
  int ls = son[u][0], rs = son[u][1];
  dfs(ls);
  dfs(rs);
  bool op = P < M;
  int op_c = min(P, M);
  for (int i = 0; i <= min(size[u], op_c); i++) {
    dp_max[u][i] = -INF;
    dp_min[u][i] = INF;
  }
  for (int i = 0; i <= min(size[ls], op_c); i++) {
    for (int j = 0; j <= min(size[rs], op_c); j++) {
      dp_max[u][i + j + op] =
          max(dp_max[u][i + j + op], dp_max[ls][i] + dp_max[rs][j]);
      dp_max[u][i + j + !op] =
          max(dp_max[u][i + j + !op], dp_max[ls][i] - dp_min[rs][j]);
      dp_min[u][i + j + op] =
          min(dp_min[u][i + j + op], dp_min[ls][i] + dp_min[rs][j]);
      dp_min[u][i + j + !op] =
          min(dp_min[u][i + j + !op], dp_min[ls][i] - dp_max[rs][j]);
    }
  }
}
int solve() {
  dfs(rt);
  return dp_max[rt][min(P, M)];
}
int main() {
  scanf("%s %d %d", s, &P, &M);
  process();
  printf("%d\n", solve());
}
