#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 5, inf = 1 << 30;
int lc[maxn], rc[maxn], val[maxn], cnt = 0, root, sz[maxn];
int par[maxn], p, m, len;
char str[maxn];
int build(int l, int r) {
  if (str[l] == '(') {
    if (par[l] == r) return build(l + 1, r - 1);
    int cur_root = cnt++;
    lc[cur_root] = build(l, par[l]);
    rc[cur_root] = build(par[l] + 2, r);
    return cur_root;
  } else {
    int cur_root = cnt++;
    if (l == r) {
      lc[cur_root] = rc[cur_root] = -1;
      val[cur_root] = str[l] - '0';
    } else {
      lc[cur_root] = build(l, l);
      rc[cur_root] = build(l + 2, r);
    }
    return cur_root;
  }
}
int build_sz(int root) {
  if (lc[root] == -1) return 0;
  return sz[root] = 1 + build_sz(lc[root]) + build_sz(rc[root]);
}
int min_[maxn][105], max_[maxn][105];
void f(int i) {
  if (lc[i] == -1)
    min_[i][0] = max_[i][0] = val[i];
  else {
    f(lc[i]), f(rc[i]);
    for (int j = 0; j <= sz[i] && j <= p; j++) {
      for (int j_l = 0; j_l <= j && j_l <= sz[lc[i]]; j_l++) {
        if (j - j_l) {
          max_[i][j] =
              std::max(max_[i][j], max_[lc[i]][j_l] + max_[rc[i]][j - j_l - 1]);
          min_[i][j] =
              std::min(min_[i][j], min_[lc[i]][j_l] + min_[rc[i]][j - j_l - 1]);
        }
        if (sz[i] - j) {
          max_[i][j] =
              std::max(max_[i][j], max_[lc[i]][j_l] - min_[rc[i]][j - j_l]);
          min_[i][j] =
              std::min(min_[i][j], min_[lc[i]][j_l] - max_[rc[i]][j - j_l]);
        }
      }
    }
  }
}
void g(int i) {
  if (lc[i] == -1)
    min_[i][0] = max_[i][0] = val[i];
  else {
    g(lc[i]), g(rc[i]);
    for (int j = 0; j <= sz[i] && j <= m; j++) {
      for (int j_l = 0; j_l <= j && j_l <= sz[lc[i]]; j_l++) {
        if (j - j_l) {
          max_[i][j] =
              std::max(max_[i][j], max_[lc[i]][j_l] - min_[rc[i]][j - j_l - 1]);
          min_[i][j] =
              std::min(min_[i][j], min_[lc[i]][j_l] - max_[rc[i]][j - j_l - 1]);
        }
        if (sz[i] - j) {
          max_[i][j] =
              std::max(max_[i][j], max_[lc[i]][j_l] + max_[rc[i]][j - j_l]);
          min_[i][j] =
              std::min(min_[i][j], min_[lc[i]][j_l] + min_[rc[i]][j - j_l]);
        }
      }
    }
  }
}
int main() {
  scanf("%s%d%d", str, &p, &m);
  len = strlen(str);
  stack<int> stk;
  for (int i = 0; i < len; i++) {
    if (str[i] == '(')
      stk.push(i);
    else if (str[i] == ')') {
      par[stk.top()] = i, par[i] = stk.top();
      stk.pop();
    }
  }
  root = build(0, len - 1);
  build_sz(root);
  for (int i = 0; i < cnt; i++)
    for (int j = 0; j < 105; j++) {
      max_[i][j] = -inf;
      min_[i][j] = inf;
    }
  int ans;
  if (p < m)
    f(root), ans = max_[root][p];
  else
    g(root), ans = max_[root][m];
  printf("%d\n", ans);
  return 0;
}
