#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
int f[2][N][105];
char s[N];
int tr[N][2], size, n, fa[N], p, m, minn, pre;
void dfs(int x) {
  if (!tr[x][0]) return;
  int l = tr[x][0], r = tr[x][1];
  dfs(l), dfs(r);
  for (int i = 0; i <= minn; i++)
    for (int j = 0; i + j <= minn; j++) {
      f[0][x][i + j + (p < m)] =
          max(f[0][x][i + j + (p < m)], f[0][l][i] + f[0][r][j]);
      f[0][x][i + j + (p >= m)] =
          max(f[0][x][i + j + (p >= m)], f[0][l][i] - f[1][r][j]);
      f[1][x][i + j + (p < m)] =
          min(f[1][x][i + j + (p < m)], f[1][l][i] + f[1][r][j]);
      f[1][x][i + j + (p >= m)] =
          min(f[1][x][i + j + (p >= m)], f[1][l][i] - f[0][r][j]);
    }
}
int main() {
  scanf("%s", s + 1);
  scanf("%d%d", &p, &m);
  memset(f[0], -63, sizeof(f[0]));
  memset(f[1], 63, sizeof(f[1]));
  minn = min(p, m);
  n = strlen(s + 1);
  size = 1;
  pre = size;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '(' || s[i] == '?') {
      tr[pre][tr[pre][0] ? 1 : 0] = ++size;
      fa[size] = pre;
      pre = size;
    } else if (s[i] == ')')
      pre = fa[pre];
    else
      f[0][size][0] = f[1][size][0] = s[i] - '0', pre = fa[pre];
  }
  dfs(1);
  printf("%d", f[0][1][minn]);
  return 0;
}
