#include <bits/stdc++.h>
const int M = 1e4 + 5;
using namespace std;
char s[10005];
int len, add, sub, minn, dp[10005][105][2], son[10005][2], dad[10005], pre = 1,
                                                                       tot = 1;
void dfs(int step) {
  int u = son[step][0];
  int v = son[step][1];
  if (!u) return;
  dfs(u);
  dfs(v);
  for (int i = 0; i <= minn; i++)
    for (int j = 0; j + i <= minn; j++) {
      dp[step][i + j + (add < sub)][0] =
          max(dp[step][i + j + (add < sub)][0], dp[u][i][0] + dp[v][j][0]);
      dp[step][i + j + (add >= sub)][0] =
          max(dp[step][i + j + (add >= sub)][0], dp[u][i][0] - dp[v][j][1]);
      dp[step][i + j + (add < sub)][1] =
          min(dp[step][i + j + (add < sub)][1], dp[u][i][1] + dp[v][j][1]);
      dp[step][i + j + (add >= sub)][1] =
          min(dp[step][i + j + (add >= sub)][1], dp[u][i][1] - dp[v][j][0]);
    }
}
int main() {
  scanf("%s", s + 1);
  scanf("%d%d", &add, &sub);
  minn = min(add, sub);
  len = strlen(s + 1);
  for (int i = 1; i < 10005; i++)
    for (int j = 0; j <= minn; j++) {
      dp[i][j][0] = -1e9;
      dp[i][j][1] = 1e9;
    }
  for (int i = 1; i <= len; i++) {
    if (s[i] == '(' || s[i] == '?') {
      son[pre][son[pre][0] ? 1 : 0] = ++tot;
      dad[tot] = pre;
      pre = tot;
    } else if (s[i] == ')')
      pre = dad[pre];
    else {
      dp[tot][0][1] = dp[tot][0][0] = s[i] - '0';
      pre = dad[pre];
    }
  }
  dfs(1);
  printf("%d\n", dp[1][minn][0]);
}
