#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e4 + 4, INF = 1e9;
string E;
int P, M, T[MAX], nops[MAX];
int nodeID = 1, ch[MAX][2];
int input(int u, int idx) {
  if (E[idx] == '(') {
    ch[u][0] = ++nodeID;
    idx = input(nodeID, idx + 1);
    ch[u][1] = ++nodeID;
    idx = input(nodeID, idx + 1);
    nops[u] = 1 + nops[ch[u][0]] + nops[ch[u][1]];
  } else {
    T[u] = E[idx] - '0';
    nops[u] = 0;
  }
  return idx + 1;
}
inline int comp(int a, int b, int st) { return st ? max(a, b) : min(a, b); }
int mem[MAX][105][2][2];
int val(int u, int p, int m, int st) {
  if (p < 0 || m < 0) return st ? -INF : INF;
  int &x = mem[u][min(p, m)][p <= m ? 0 : 1][st];
  if (x != -1) return x;
  if (T[u] != 0) return x = T[u];
  x = st ? -INF : INF;
  const int L = ch[u][0], R = ch[u][1];
  assert(min(m, p) <= 100);
  if (p <= m) {
    for (int lp = 0; lp <= p; ++lp) {
      int rp = p - lp - 1;
      x = comp(x, val(L, lp, nops[L] - lp, st) + val(R, rp, nops[R] - rp, st),
               st);
      rp = p - lp;
      x = comp(x,
               val(L, lp, nops[L] - lp, st) - val(R, rp, nops[R] - rp, st ^ 1),
               st);
    }
  } else {
    for (int lm = 0; lm <= m; ++lm) {
      int rm = m - lm - 1;
      x = comp(x,
               val(L, nops[L] - lm, lm, st) - val(R, nops[R] - rm, rm, st ^ 1),
               st);
      rm = m - lm;
      x = comp(x, val(L, nops[L] - lm, lm, st) + val(R, nops[R] - rm, rm, st),
               st);
    }
  }
  return x;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> E;
  input(1, 0);
  cin >> P >> M;
  memset(mem, -1, sizeof mem);
  cout << val(1, P, M, 1) << "\n";
}
