#include <bits/stdc++.h>
using namespace std;
const double g = 10.0, eps = 1e-12;
const int N = 10000 + 10, maxn = 1200000 + 10, inf = 0x3f3f3f3f,
          INF = 0x3f3f3f3f3f3f3f3f;
char s[N];
int dp[N][110][2], val[N], cnt;
int dfs(int l, int r, int ma, int op, int ii) {
  ii = ++cnt;
  for (int i = l; i <= r; i++) val[i] = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] == '(')
      val[i] = val[i - 1] + 1;
    else if (s[i] == ')')
      val[i] = val[i - 1] - 1;
    else
      val[i] = val[i - 1];
  }
  int mi = 1e5;
  for (int i = l; i <= r; i++)
    if (s[i] == '?') mi = min(mi, val[i]);
  int id = -1;
  for (int i = r; i >= l; i--) {
    if (s[i] == '?' && mi == val[i]) {
      id = i;
      break;
    }
  }
  for (int i = 0; i <= ma; i++) {
    dp[ii][i][0] = inf;
    dp[ii][i][1] = -inf;
  }
  if (id == -1) {
    int x = 0;
    for (int i = l; i <= r; i++)
      if ('0' <= s[i] && s[i] <= '9') x = x * 10 + s[i] - '0';
    dp[ii][0][0] = dp[ii][0][1] = x;
  } else {
    int x1 = dfs(l, id - 1, ma, op, ii), x2 = dfs(id + 1, r, ma, op, ii);
    for (int i = 0; i <= ma; i++)
      if (dp[x1][i][1] > -inf)
        for (int j = 0; i + j + 1 <= ma; j++)
          if (dp[x2][j][1] >= -inf) {
            if (op == 1) {
              dp[ii][i + j + 1][1] =
                  max(dp[ii][i + j + 1][1], dp[x1][i][1] + dp[x2][j][1]);
              dp[ii][i + j + 1][0] =
                  min(dp[ii][i + j + 1][0], dp[x1][i][0] + dp[x2][j][0]);
              dp[ii][i + j][1] =
                  max(dp[ii][i + j][1], dp[x1][i][1] - dp[x2][j][0]);
              dp[ii][i + j][0] =
                  min(dp[ii][i + j][0], dp[x1][i][0] - dp[x2][j][1]);
            } else {
              dp[ii][i + j + 1][1] =
                  max(dp[ii][i + j + 1][1], dp[x1][i][1] - dp[x2][j][0]);
              dp[ii][i + j + 1][0] =
                  min(dp[ii][i + j + 1][0], dp[x1][i][0] - dp[x2][j][1]);
              dp[ii][i + j][1] =
                  max(dp[ii][i + j][1], dp[x1][i][1] + dp[x2][j][1]);
              dp[ii][i + j][0] =
                  min(dp[ii][i + j][0], dp[x1][i][0] + dp[x2][j][0]);
            }
          }
  }
  return ii;
}
int main() {
  int n;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  cnt = 0;
  int p, m;
  scanf("%d%d", &p, &m);
  if (p <= 100) {
    dfs(1, n, 105, 1, 1);
    printf("%d\n", dp[1][p][1]);
  } else {
    dfs(1, n, 105, -1, 1);
    printf("%d\n", dp[1][m][1]);
  }
  return 0;
}
