#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5;
const int OPMAX = 1e2;
const int INF = (1 << 30);
struct Tree {
  int no;
  int maxx[1 + OPMAX];
  int minn[1 + OPMAX];
};
int n, p, m, k;
int opcase;
string s;
stack<int> st;
Tree arb[1 + NMAX];
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  cin >> p >> m;
  n = s.size();
  if (m <= 100)
    opcase = 2;
  else
    opcase = 1;
  for (int i = 0; i < n; i++) {
    if (isdigit(s[i])) {
      k++;
      st.push(k);
      arb[k].no = 0;
      arb[k].maxx[0] = (s[i] - '0');
      arb[k].minn[0] = (s[i] - '0');
    } else if (s[i] == ')') {
      int ri = st.top();
      st.pop();
      int le = st.top();
      st.pop();
      k++;
      st.push(k);
      arb[k].no = arb[le].no + arb[ri].no + 1;
      int lim1 = min(arb[k].no, OPMAX);
      for (int j1 = 0; j1 <= lim1; j1++) {
        arb[k].maxx[j1] = -INF;
        arb[k].minn[j1] = INF;
        int lim2 = min(arb[le].no, j1);
        for (int j2 = 0; j2 <= lim2; j2++) {
          if (opcase == 1) {
            if (j1 != j2 && j1 - j2 - 1 <= arb[ri].no) {
              arb[k].maxx[j1] =
                  max(arb[k].maxx[j1],
                      arb[le].maxx[j2] + arb[ri].maxx[j1 - j2 - 1]);
              arb[k].minn[j1] =
                  min(arb[k].minn[j1],
                      arb[le].minn[j2] + arb[ri].minn[j1 - j2 - 1]);
            }
            if (j1 - j2 <= arb[ri].no) {
              arb[k].maxx[j1] = max(arb[k].maxx[j1],
                                    arb[le].maxx[j2] - arb[ri].minn[j1 - j2]);
              arb[k].minn[j1] = min(arb[k].minn[j1],
                                    arb[le].minn[j2] - arb[ri].maxx[j1 - j2]);
            }
          } else {
            if (j1 != j2 && j1 - j2 - 1 <= arb[ri].no) {
              arb[k].maxx[j1] =
                  max(arb[k].maxx[j1],
                      arb[le].maxx[j2] - arb[ri].minn[j1 - j2 - 1]);
              arb[k].minn[j1] =
                  min(arb[k].minn[j1],
                      arb[le].minn[j2] - arb[ri].maxx[j1 - j2 - 1]);
            }
            if (j1 - j2 <= arb[ri].no) {
              arb[k].maxx[j1] = max(arb[k].maxx[j1],
                                    arb[le].maxx[j2] + arb[ri].maxx[j1 - j2]);
              arb[k].minn[j1] = min(arb[k].minn[j1],
                                    arb[le].minn[j2] + arb[ri].minn[j1 - j2]);
            }
          }
        }
      }
    }
  }
  if (opcase == 1)
    cout << arb[k].maxx[p] << '\n';
  else
    cout << arb[k].maxx[m] << '\n';
  return 0;
}
