#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int nmax = 1e4 + 5;
char s[nmax];
int paran_match[nmax];
int op_idx[nmax];
int n, p, m;
int dpMax[nmax][105];
int dpMin[nmax][105];
void pre() {
  stack<int> st;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '(') {
      st.push(i);
    } else if (s[i] == ')') {
      paran_match[st.top()] = i;
      st.pop();
    } else if (s[i] == '?') {
      op_idx[st.top()] = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 105; j++) dpMax[i][j] = -inf, dpMin[i][j] = inf;
    if (s[i] >= '0' && s[i] <= '9') dpMax[i][0] = dpMin[i][0] = s[i] - '0';
  }
}
void recurse(int p, int m, char Plus, int l) {
  if (s[l] >= '0' && s[l] <= '9') return;
  assert(s[l] == '(');
  int nl = op_idx[l] + 1;
  recurse(p, m, Plus, l + 1);
  recurse(p, m, Plus, nl);
  for (int j = 0; j <= p; j++) {
    for (int k = 0; k <= j; k++) {
      if (dpMax[l + 1][k] != -inf) {
        if (j - k - ('+' == Plus) >= 0 &&
            dpMax[nl][j - k - ('+' == Plus)] != -inf)
          dpMax[l][j] = max(dpMax[l][j],
                            dpMax[l + 1][k] + dpMax[nl][j - k - ('+' == Plus)]);
        if (j - k - ('-' == Plus) >= 0 &&
            dpMin[nl][j - k - ('-' == Plus)] != -inf)
          dpMax[l][j] = max(dpMax[l][j],
                            dpMax[l + 1][k] - dpMin[nl][j - k - ('-' == Plus)]);
      }
      if (dpMin[l + 1][k] != inf) {
        if (j - k - ('+' == Plus) >= 0 &&
            dpMin[nl][j - k - ('+' == Plus)] != -inf)
          dpMin[l][j] = min(dpMin[l][j],
                            dpMin[l + 1][k] + dpMin[nl][j - k - ('+' == Plus)]);
        if (j - k - ('-' == Plus) >= 0 &&
            dpMax[nl][j - k - ('-' == Plus)] != -inf)
          dpMin[l][j] = min(dpMin[l][j],
                            dpMin[l + 1][k] - dpMax[nl][j - k - ('-' == Plus)]);
      }
    }
  }
}
void solve(int p, int m, char Plus) {
  pre();
  recurse(p, m, Plus, 1);
  cout << dpMax[1][p] << '\n';
}
int main() {
  cin >> (s + 1);
  n = strlen(s + 1);
  cin >> p >> m;
  if (p < m)
    solve(p, m, '+');
  else
    solve(m, p, '-');
  return 0;
}
