#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, d, c;
  node() {
    l = r = d = -1;
    c = 0;
  }
} a[100010];
int cnt = 0, dp1[100010][110], dp2[100010][110], flag, p, m;
char s[100010];
void dfs(int x) {
  if (a[x].d != 10) {
    dp1[x][0] = dp2[x][0] = a[x].d;
    return;
  }
  int l = a[x].l, r = a[x].r;
  dfs(l);
  dfs(r);
  if (flag) {
    for (int i = 0; i <= a[x].c; i++)
      for (int j = 0; j <= a[l].c && j <= i; j++)
        if (i - j <= a[r].c) {
          dp1[x][i] = max(dp1[x][i], dp1[l][j] - dp2[r][i - j]);
          dp2[x][i] = min(dp2[x][i], dp2[l][j] - dp1[r][i - j]);
          if (i <= a[x].c - 1) {
            dp1[x][i + 1] = max(dp1[x][i + 1], dp1[l][j] + dp1[r][i - j]);
            dp2[x][i + 1] = min(dp2[x][i + 1], dp2[l][j] + dp2[r][i - j]);
          }
        }
  } else {
    for (int i = 0; i <= a[x].c; i++)
      for (int j = 0; j <= a[l].c && j <= i; j++)
        if (i - j <= a[r].c) {
          dp1[x][i] = max(dp1[x][i], dp1[l][j] + dp1[r][i - j]);
          dp2[x][i] = min(dp2[x][i], dp2[l][j] + dp2[r][i - j]);
          if (i <= a[x].c - 1) {
            dp1[x][i + 1] = max(dp1[x][i + 1], dp1[l][j] - dp2[r][i - j]);
            dp2[x][i + 1] = min(dp2[x][i + 1], dp2[l][j] - dp1[r][i - j]);
          }
        }
  }
}
int build(int l, int r) {
  if (l == r) {
    a[++cnt].d = s[l] - '0';
    a[cnt].c = 0;
    return cnt;
  }
  int num = 0, mid;
  for (int i = l; i <= r; i++) {
    if (s[i] == '(') num++;
    if (s[i] == ')') num--;
    if (num == 1 && s[i] == '?') {
      mid = i;
      break;
    }
  }
  int t = ++cnt;
  a[t].d = 10;
  a[t].l = build(l + 1, mid - 1);
  a[t].r = build(mid + 1, r - 1);
  a[t].c = a[a[t].l].c + a[a[t].r].c + 1;
  return t;
}
int main() {
  scanf("%s", s);
  scanf("%d%d", &p, &m);
  int len = strlen(s);
  build(0, len - 1);
  memset(dp2, 0x3f3f3f3f, sizeof(dp2));
  memset(dp1, -0x3f3f3f3f, sizeof(dp1));
  flag = p < m ? 1 : 0;
  dfs(1);
  cout << dp1[1][min(p, m)] << endl;
  return 0;
}
