#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int dp[2][10010][110];
char ch[10010];
int son[10010][2], cnt, fa[10010], p, m, pre, mi;
void dfs(int x) {
  if (!son[x][0]) return;
  int l = son[x][0], r = son[x][1];
  dfs(l), dfs(r);
  for (int i = 0; i <= mi; i++) {
    for (int j = 0; i + j <= mi; j++) {
      dp[0][x][i + j + (p < m)] =
          max(dp[0][x][i + j + (p < m)], dp[0][l][i] + dp[0][r][j]);
      dp[0][x][i + j + (p >= m)] =
          max(dp[0][x][i + j + (p >= m)], dp[0][l][i] - dp[1][r][j]);
      dp[1][x][i + j + (p < m)] =
          min(dp[1][x][i + j + (p < m)], dp[1][l][i] + dp[1][r][j]);
      dp[1][x][i + j + (p >= m)] =
          min(dp[1][x][i + j + (p >= m)], dp[1][l][i] - dp[0][r][j]);
    }
  }
}
int main() {
  while (~scanf("%s", ch)) {
    scanf("%d%d", &p, &m);
    mi = min(p, m);
    int len = strlen(ch);
    cnt = pre = 1;
    son[1][0] = son[1][1] = 0;
    memset(dp[0], -INF, sizeof dp[0]);
    memset(dp[1], INF, sizeof dp[1]);
    for (int i = 0; i < len; i++) {
      if (ch[i] == '(' || ch[i] == '?') {
        son[pre][son[pre][0] ? 1 : 0] = ++cnt;
        son[cnt][0] = son[cnt][1] = 0;
        fa[cnt] = pre;
        pre = cnt;
      } else if (ch[i] == ')')
        pre = fa[pre];
      else {
        dp[0][cnt][0] = dp[1][cnt][0] = ch[i] - '0';
        pre = fa[pre];
      }
    }
    dfs(1);
    printf("%d", dp[0][1][mi]);
  }
  return 0;
}
