#include <bits/stdc++.h>
using namespace std;
struct Node {
  int fa, ch[2];
  vector<int> min, max;
  Node() : min(128, 1e9), max(128, -1e9) {}
} v[10010];
char s[10010];
int p, m, pm, tot;
void dfs(int k) {
  if (!k || !v[k].min[0]) return;
  int l = v[k].ch[0], r = v[k].ch[1];
  dfs(l), dfs(r);
  for (int i = 0; i <= pm; ++i)
    for (int j = 0; j + i <= pm; ++j) {
      if (v[k].max[i + j + (p <= m)] < v[l].max[i] + v[r].max[j])
        v[k].max[i + j + (p <= m)] = v[l].max[i] + v[r].max[j];
      if (v[k].max[i + j + (p > m)] < v[l].max[i] - v[r].min[j])
        v[k].max[i + j + (p > m)] = v[l].max[i] - v[r].min[j];
      if (v[k].min[i + j + (p <= m)] > v[l].min[i] + v[r].min[j])
        v[k].min[i + j + (p <= m)] = v[l].min[i] + v[r].min[j];
      if (v[k].min[i + j + (p > m)] > v[l].min[i] - v[r].max[j])
        v[k].min[i + j + (p > m)] = v[l].min[i] - v[r].max[j];
    }
}
int main() {
  scanf("%s%d%d", s + 1, &p, &m);
  pm = min(p, m);
  for (int i = 1, pre = ++tot; s[i]; ++i) {
    if (s[i] == '?' || s[i] == '(') {
      v[pre].ch[v[pre].ch[0] ? 1 : 0] = ++tot;
      v[tot].fa = pre;
      pre = tot;
    } else if (s[i] == ')')
      pre = v[pre].fa;
    else {
      v[pre].min[0] = v[pre].max[0] = s[i] - '0';
      pre = v[pre].fa;
    }
  }
  dfs(1);
  printf("%d", v[1].max[pm]);
}
