#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
struct node {
  int l, r, val;
  node(){};
  node(int val) : l(-1), r(-1), val(val){};
} nodes[10005];
string e;
int num, memo[10005][105][2], ops[10005];
bool visited[10005][105];
int dfs(int cur) {
  if (nodes[cur].val == -1) {
    ops[cur] = 1 + dfs(nodes[cur].l) + dfs(nodes[cur].r);
  } else
    ops[cur] = 0;
  return ops[cur];
}
pair<int, int> dfs(int cur, int p, int m, int which) {
  assert(p + m == ops[cur]);
  if (nodes[cur].val != -1) return {nodes[cur].val, nodes[cur].val};
  int lp, lm, rp, rm, ln = nodes[cur].l, rn = nodes[cur].r;
  pair<int, int> l, r;
  if (which) {
    if (visited[cur][m]) return {memo[cur][m][0], memo[cur][m][1]};
    visited[cur][m] = 1;
    memo[cur][m][0] = -inf;
    memo[cur][m][1] = inf;
    if (m) {
      for (int i = 0; i < m; ++i) {
        lm = i;
        lp = ops[ln] - lm;
        rm = m - 1 - i;
        rp = ops[rn] - rm;
        if (lp < 0 || rp < 0 || lp + rp > p) continue;
        l = dfs(ln, lp, lm, 1);
        r = dfs(rn, rp, rm, 1);
        memo[cur][m][0] = max(memo[cur][m][0], l.first - r.second);
        memo[cur][m][0] = max(memo[cur][m][0], l.second - r.second);
        memo[cur][m][0] = max(memo[cur][m][0], l.first - r.first);
        memo[cur][m][0] = max(memo[cur][m][0], l.second - r.first);
        memo[cur][m][1] = min(memo[cur][m][1], l.first - r.second);
        memo[cur][m][1] = min(memo[cur][m][1], l.second - r.second);
        memo[cur][m][1] = min(memo[cur][m][1], l.first - r.first);
        memo[cur][m][1] = min(memo[cur][m][1], l.second - r.first);
      }
    }
    if (p) {
      for (int i = 0; i <= m; ++i) {
        lm = i;
        lp = ops[ln] - lm;
        rm = m - i;
        rp = ops[rn] - rm;
        if (lp < 0 || rp < 0 || lp + rp > p - 1) continue;
        l = dfs(ln, lp, lm, 1);
        r = dfs(rn, rp, rm, 1);
        memo[cur][m][0] = max(memo[cur][m][0], l.first + r.second);
        memo[cur][m][0] = max(memo[cur][m][0], l.second + r.second);
        memo[cur][m][0] = max(memo[cur][m][0], l.first + r.first);
        memo[cur][m][0] = max(memo[cur][m][0], l.second + r.first);
        memo[cur][m][1] = min(memo[cur][m][1], l.first + r.second);
        memo[cur][m][1] = min(memo[cur][m][1], l.second + r.second);
        memo[cur][m][1] = min(memo[cur][m][1], l.first + r.first);
        memo[cur][m][1] = min(memo[cur][m][1], l.second + r.first);
      }
    }
    assert(memo[cur][m][0] >= memo[cur][m][1]);
    return {memo[cur][m][0], memo[cur][m][1]};
  } else {
    if (visited[cur][p]) return {memo[cur][p][0], memo[cur][p][1]};
    visited[cur][p] = 1;
    memo[cur][p][0] = -inf;
    memo[cur][p][1] = inf;
    if (m) {
      for (int i = 0; i <= p; ++i) {
        lp = i;
        lm = ops[ln] - lp;
        rp = p - i;
        rm = ops[rn] - rp;
        if (lm < 0 || rm < 0 || lm + rm > m - 1) continue;
        l = dfs(ln, lp, lm, 0);
        r = dfs(rn, rp, rm, 0);
        memo[cur][p][0] = max(memo[cur][p][0], l.first - r.second);
        memo[cur][p][0] = max(memo[cur][p][0], l.second - r.second);
        memo[cur][p][0] = max(memo[cur][p][0], l.first - r.first);
        memo[cur][p][0] = max(memo[cur][p][0], l.second - r.first);
        memo[cur][p][1] = min(memo[cur][p][1], l.first - r.second);
        memo[cur][p][1] = min(memo[cur][p][1], l.second - r.second);
        memo[cur][p][1] = min(memo[cur][p][1], l.first - r.first);
        memo[cur][p][1] = min(memo[cur][p][1], l.second - r.first);
      }
    }
    if (p) {
      for (int i = 0; i < p; ++i) {
        lp = i;
        lm = ops[ln] - lp;
        rp = p - 1 - i;
        rm = ops[rn] - rp;
        if (lm < 0 || rm < 0 || lm + rm > m) continue;
        l = dfs(ln, lp, lm, 0);
        r = dfs(rn, rp, rm, 0);
        memo[cur][p][0] = max(memo[cur][p][0], l.first + r.second);
        memo[cur][p][0] = max(memo[cur][p][0], l.second + r.second);
        memo[cur][p][0] = max(memo[cur][p][0], l.first + r.first);
        memo[cur][p][0] = max(memo[cur][p][0], l.second + r.first);
        memo[cur][p][1] = min(memo[cur][p][1], l.first + r.second);
        memo[cur][p][1] = min(memo[cur][p][1], l.second + r.second);
        memo[cur][p][1] = min(memo[cur][p][1], l.first + r.first);
        memo[cur][p][1] = min(memo[cur][p][1], l.second + r.first);
      }
    }
    assert(memo[cur][p][0] >= memo[cur][p][1]);
    return {memo[cur][p][0], memo[cur][p][1]};
  }
}
int create(int l, int r) {
  int cur = num;
  if (e[l] == '(' && e[r] == ')') {
    int cnt = 0;
    for (int i = l + 1; i < r; ++i) {
      if (e[i] == '(')
        ++cnt;
      else if (e[i] == ')')
        --cnt;
      else if (e[i] == '?' && !cnt) {
        nodes[num++] = node(-1);
        nodes[cur].l = create(l + 1, i - 1);
        nodes[cur].r = create(i + 1, r - 1);
      }
    }
  } else {
    assert(l == r);
    nodes[num++] = node(e[l] - '0');
  }
  return cur;
}
void print(int cur) {
  cout << "at " << cur << " values " << nodes[cur].val << ": " << nodes[cur].l
       << " " << nodes[cur].r << "\n";
  if (nodes[cur].val == -1) {
    print(nodes[cur].l);
    print(nodes[cur].r);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int p, m, n, root;
  while (cin >> e >> p >> m) {
    num = 0;
    n = e.length();
    root = create(0, n - 1);
    dfs(root);
    memset(visited, 0, sizeof(visited));
    if (p <= 100)
      cout << dfs(root, p, m, 0).first << "\n";
    else
      cout << dfs(root, p, m, 1).first << "\n";
  }
  return 0;
}
