#include <bits/stdc++.h>
using namespace std;
template <typename T>
string tos(T a) {
  stringstream ss;
  string ret;
  ss << a;
  ss >> ret;
  return ret;
}
void read(int &_a) { int temp = scanf("%d", &_a); }
void read(int &_a, int &_b) { int temp = scanf("%d %d", &_a, &_b); }
void read(int &_a, int &_b, int &_c) {
  int temp = scanf("%d %d %d", &_a, &_b, &_c);
}
const int LM = 1e4 + 7;
const int LM2 = 109;
string st;
int P, M;
struct node {
  int l, r, v, cnt;
  node() : l(-1), r(-1), v(0), cnt(0) {}
};
node nds[LM];
int ndcnt, rt, MX[LM][LM2], MN[LM][LM2];
stack<int> stt;
int main() {
  while (cin >> st >> P >> M) {
    ndcnt = 0;
    int l = st.size();
    while (stt.size() > 0) stt.pop();
    for (int(i) = (0); (i) < (LM); (i)++)
      for (int(j) = (0); (j) < (LM2); (j)++) {
        MX[i][j] = -214748364;
        MN[i][j] = 214748364;
      }
    for (int(i) = (0); (i) < (l); (i)++) {
      if (st[i] == '(' || st[i] == '?') continue;
      if (st[i] == ')') {
        int b = stt.top();
        stt.pop();
        int a = stt.top();
        stt.pop();
        int ind = ndcnt++;
        node &nw = nds[ind];
        nw.l = a;
        nw.r = b;
        nw.cnt = nds[a].cnt + nds[b].cnt + 1;
        rt = ind;
        stt.push(ind);
      } else {
        int ind = ndcnt++;
        node &nw = nds[ind];
        nw.v = st[i] - '0';
        stt.push(ind);
      }
    }
    int SOP = min(P, M);
    for (int(ii) = (0); (ii) < (rt + 1); (ii)++) {
      node &nw = nds[ii];
      int l = nw.l;
      int r = nw.r;
      int cnt = nw.cnt;
      for (int(have) = (0); (have) < (SOP + 1); (have)++) {
        if (nw.v > 0) {
          if (have == 0) MX[ii][have] = MN[ii][have] = nw.v;
          continue;
        }
        for (int(lf) = (0); (lf) < (have + 1); (lf)++) {
          if (P < M && lf < have)
            MX[ii][have] = max(MX[ii][have], MX[l][lf] + MX[r][have - lf - 1]);
          if (P < M && have < cnt)
            MX[ii][have] = max(MX[ii][have], MX[l][lf] - MN[r][have - lf]);
          if (P >= M && have < cnt)
            MX[ii][have] = max(MX[ii][have], MX[l][lf] + MX[r][have - lf]);
          if (P >= M && lf < have)
            MX[ii][have] = max(MX[ii][have], MX[l][lf] - MN[r][have - lf - 1]);
          if (P < M && lf < have)
            MN[ii][have] = min(MN[ii][have], MN[l][lf] + MN[r][have - lf - 1]);
          if (P < M && have < cnt)
            MN[ii][have] = min(MN[ii][have], MN[l][lf] - MX[r][have - lf]);
          if (P >= M && have < cnt)
            MN[ii][have] = min(MN[ii][have], MN[l][lf] + MN[r][have - lf]);
          if (P >= M && lf < have)
            MN[ii][have] = min(MN[ii][have], MN[l][lf] - MX[r][have - lf - 1]);
        }
      }
    }
    cout << MX[rt][SOP] << endl;
  }
  return 0;
}
