#include <bits/stdc++.h>
using namespace std;
string s;
int p, m, tree[10010][2], f[10010][110], g[10010][110], fa[10010], mini;
void dfs(int u) {
  if (!tree[u][0]) {
    return;
  }
  int l, r;
  l = tree[u][0];
  r = tree[u][1];
  dfs(l);
  dfs(r);
  int i, j;
  for (i = 0; i <= mini; i++) {
    for (j = 0; i + j <= mini; j++) {
      f[u][i + j + (p < m)] = max(f[u][i + j + (p < m)], f[l][i] + f[r][j]);
      f[u][i + j + (p >= m)] = max(f[u][i + j + (p >= m)], f[l][i] - g[r][j]);
      g[u][i + j + (p < m)] = min(g[u][i + j + (p < m)], g[l][i] + g[r][j]);
      g[u][i + j + (p >= m)] = min(g[u][i + j + (p >= m)], g[l][i] - f[r][j]);
    }
  }
}
int main(void) {
  std::ios::sync_with_stdio(false);
  cin >> s >> p >> m;
  int i, l, now, id;
  now = id = 1;
  l = s.length();
  memset(f, -0x3f, sizeof(f));
  memset(g, 0x3f, sizeof(f));
  for (i = 0; i < l; i++) {
    if (s[i] == '(' || s[i] == '?') {
      if (!tree[now][0]) {
        tree[now][0] = ++id;
        fa[id] = now;
        now = id;
      } else {
        tree[now][1] = ++id;
        fa[id] = now;
        now = id;
      }
    } else if (s[i] == ')') {
      now = fa[now];
    } else {
      f[id][0] = g[id][0] = s[i] - '0';
      now = fa[now];
    }
  }
  mini = min(p, m);
  dfs(1);
  printf("%d\n", f[1][mini]);
  return 0;
}
