#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int maxn = 1e5 + 100;
const int maxsign = 110;
int dp[2][maxn][maxsign];
char ch[maxn];
int son[maxn][2], fa[maxn], cnt, pre, p, m, mi, len;
void init() {
  mi = min(p, m);
  cnt = pre = 1;
  len = strlen(ch);
  son[1][0] = son[1][1] = 0;
  memset(dp[0], -inf, sizeof(dp[0]));
  memset(dp[1], inf, sizeof(dp[1]));
  memset(son, 0, sizeof(son));
}
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() {
  scanf("%s", ch);
  scanf("%d %d", &p, &m);
  init();
  for (int i = 0; i < len; i++) {
    if (ch[i] == '(' || ch[i] == '?') {
      son[pre][son[pre][0] ? 1 : 0] = ++cnt;
      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[cnt];
    }
  }
  dfs(1);
  printf("%d", dp[0][1][mi]);
  return 0;
}
