#include <bits/stdc++.h>
using std::max;
using std::min;
char str[10010];
int fa[10010], son[10010], brother[10010], tot;
int key[10010], change[10010], pos[10010];
int f[10010][110][2], siz[10010], p, m;
int bak[10010][110][2];
void dfs(int now, int flag) {
  for (int i = 0; i <= 100; ++i) {
    f[now][i][0] = 99999999;
    f[now][i][1] = -99999999;
  }
  if (son[now] == 0) {
    f[now][0][0] = f[now][0][1] = str[pos[now]] - '0';
  } else {
    siz[now] = 0;
    for (int x = son[now]; x != 0; x = brother[x]) {
      dfs(x, flag);
      siz[now] += siz[x];
      for (int i = 0; i <= 100; ++i) {
        bak[now][i][0] = f[now][i][0];
        bak[now][i][1] = f[now][i][1];
        f[now][i][0] = 99999999;
        f[now][i][1] = -99999999;
      }
      if (change[x]) {
        siz[now]++;
        for (int i = 0; i <= 100; ++i) {
          for (int j = 0; j <= 100; ++j) {
            if (i + j > 100) break;
            if (flag) {
              f[now][i + j][0] =
                  min(f[now][i + j][0], bak[now][i][0] + f[x][j][0]);
              f[now][i + j][1] =
                  max(f[now][i + j][1], bak[now][i][1] + f[x][j][1]);
              f[now][i + j + 1][0] =
                  min(f[now][i + j + 1][0], bak[now][i][0] - f[x][j][1]);
              f[now][i + j + 1][1] =
                  max(f[now][i + j + 1][1], bak[now][i][1] - f[x][j][0]);
            } else {
              f[now][i + j + 1][0] =
                  min(f[now][i + j + 1][0], bak[now][i][0] + f[x][j][0]);
              f[now][i + j + 1][1] =
                  max(f[now][i + j + 1][1], bak[now][i][1] + f[x][j][1]);
              f[now][i + j][0] =
                  min(f[now][i + j][0], bak[now][i][0] - f[x][j][1]);
              f[now][i + j][1] =
                  max(f[now][i + j][1], bak[now][i][1] - f[x][j][0]);
            }
          }
        }
      } else {
        for (int i = 0; i <= 100; ++i) {
          f[now][i][0] = f[x][i][0];
          f[now][i][1] = f[x][i][1];
        }
      }
    }
  }
}
int main() {
  scanf("%s", str);
  scanf("%d%d", &p, &m);
  int now = 0, flag = p > m;
  int len = strlen(str);
  for (int i = len - 1; i >= 0; --i) {
    if (str[i] == '?') {
    } else if (str[i] == '(') {
      now = fa[now];
    } else {
      int x = ++tot;
      pos[x] = i;
      if (i == len - 1 || str[i + 1] == ')') {
        fa[x] = now;
        brother[x] = son[now];
        son[now] = x;
      } else {
        fa[x] = fa[now];
        brother[x] = now;
        son[fa[x]] = x;
      }
      now = x;
    }
  }
  for (int i = 1; i <= tot; ++i)
    if (son[fa[i]] != i) change[i] = 1;
  dfs(1, flag);
  printf("%d\n", f[1][flag ? m : p][1]);
}
