#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e4 + 100;
char s[maxn];
int dp[maxn][110][2];
int ch[maxn][2], fa[maxn], sz[maxn];
int pre = 0, now = 0, cnt = 0;
int p, m;
void dfs(int x) {
  int lson = ch[x][0], rson = ch[x][1];
  if (dp[x][0][0] == dp[x][0][1]) return;
  dfs(lson), dfs(rson);
  sz[x] = sz[lson] + sz[rson] + 1;
  for (int i = 0; i <= min(min(p, m), sz[lson]); i++) {
    for (int j = 0; j + i <= min(min(p, m), sz[x] - 1); j++) {
      if (sz[x] - 1 - (i + j) > max(p, m)) continue;
      if (sz[x] - (i + j) <= max(p, m)) {
        if (p < m)
          dp[x][i + j][0] =
              min(dp[x][i + j][0], dp[lson][i][0] - dp[rson][j][1]),
                    dp[x][i + j][1] =
                        max(dp[x][i + j][1], dp[lson][i][1] - dp[rson][j][0]);
        else
          dp[x][i + j][0] =
              min(dp[x][i + j][0], dp[lson][i][0] + dp[rson][j][0]),
                    dp[x][i + j][1] =
                        max(dp[x][i + j][1], dp[lson][i][1] + dp[rson][j][1]);
      }
      if (i + j < min(p, m)) {
        if (p < m)
          dp[x][i + j + 1][0] =
              min(dp[x][i + j + 1][0], dp[lson][i][0] + dp[rson][j][0]),
                        dp[x][i + j + 1][1] =
                            max(dp[x][i + j + 1][1],
                                dp[lson][i][1] + dp[rson][j][1]);
        else
          dp[x][i + j + 1][0] =
              min(dp[x][i + j + 1][0], dp[lson][i][0] - dp[rson][j][1]),
                        dp[x][i + j + 1][1] =
                            max(dp[x][i + j + 1][1],
                                dp[lson][i][1] - dp[rson][j][0]);
      }
    }
  }
}
int main() {
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  scanf("%d%d", &p, &m);
  for (int i = 0; i <= len + 10; i++) {
    for (int j = 0; j <= min(p, m) + 5; j++)
      dp[i][j][1] = -0xfffffff, dp[i][j][0] = 0xfffffff;
  }
  for (int i = 1; i <= len; i++) {
    if (s[i] == '(') {
      ch[pre][ch[pre][0] ? 1 : 0] = ++now;
      fa[now] = pre;
      pre = now;
    } else if (s[i] == ')')
      pre = fa[pre];
    else if (s[i] != '?')
      ch[pre][ch[pre][0] ? 1 : 0] = ++now,
                               dp[now][0][0] = dp[now][0][1] = s[i] - '0';
  }
  dfs(1);
  printf("%d\n", dp[1][min(p, m)][1]);
}
