#include <bits/stdc++.h>
using namespace std;
const int maxn = 10100;
const int inf = 0x3f3f3f3f;
struct Node {
  int lc, rc, val;
} o[maxn];
int op[2], ty, dp[2][maxn][110], o_cnt, q, M;
char s[maxn];
int NewNode() {
  int id = ++o_cnt;
  o[id].lc = o[id].rc = o[id].val = 0;
  return id;
}
void Build(int u) {
  char c = s[q++];
  if ('0' < c && c <= '9') {
    o[u].val = c - '0';
    return;
  } else if (c != '(')
    1 / 0;
  Build(o[u].lc = NewNode());
  c = s[q++];
  if (c != '?') 1 / 0;
  Build(o[u].rc = NewNode());
  c = s[q++];
  if (c != ')') 1 / 0;
}
bool IsSuit(int x, int y) {
  if (x == inf || x == -inf)
    return false;
  else if (y == inf || y == -inf)
    return false;
  else
    return true;
}
int OP(int flag, int x, int y) {
  if (flag ^ ty)
    return x - y;
  else
    return x + y;
}
void DFS(int u) {
  if (o[u].val) {
    for (int i = 0; i <= M; i++) {
      dp[0][u][i] = i == 0 ? o[u].val : inf;
      dp[1][u][i] = i == 0 ? o[u].val : -inf;
    }
  } else {
    DFS(o[u].lc);
    DFS(o[u].rc);
    for (int i = 0; i <= M; i++) {
      dp[0][u][i] = inf;
      dp[1][u][i] = -inf;
      for (int j = 0; j <= i; j++)
        for (int ii = 0; ii < 2; ii++)
          for (int jj = 0; jj < 2; jj++) {
            int x = dp[ii][o[u].lc][j], y = dp[jj][o[u].rc][i - j];
            if (IsSuit(x, y)) {
              dp[0][u][i] = min(dp[0][u][i], OP(1, x, y));
              dp[1][u][i] = max(dp[1][u][i], OP(1, x, y));
            }
            if (i - j - 1 >= 0) {
              x = dp[ii][o[u].lc][j], y = dp[jj][o[u].rc][i - j - 1];
              if (IsSuit(x, y)) {
                dp[0][u][i] = min(dp[0][u][i], OP(0, x, y));
                dp[1][u][i] = max(dp[1][u][i], OP(0, x, y));
              }
            }
          }
    }
  }
}
int main() {
  scanf("%s", s);
  scanf("%d%d", &op[0], &op[1]);
  ty = op[0] > op[1];
  M = op[ty];
  int rt = NewNode();
  Build(rt);
  DFS(rt);
  printf("%d\n", dp[1][rt][op[ty]]);
  return 0;
}
