#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int M = 10005;
int read() {
  int x = 0, flag = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * flag;
}
int n, p, m, k, tot, pre, f[2][M][N], fa[M], son[M][2];
char s[M];
void dfs(int u) {
  if (!u) return;
  dfs(son[u][0]);
  dfs(son[u][1]);
  for (int i = 0; i <= k; i++)
    for (int j = 0; i + j <= k; j++) {
      f[0][u][i + j + (p >= m)] = max(f[0][u][i + j + (p >= m)],
                                      f[0][son[u][0]][i] - f[1][son[u][1]][j]);
      f[1][u][i + j + (p >= m)] = min(f[1][u][i + j + (p >= m)],
                                      f[1][son[u][0]][i] - f[0][son[u][1]][j]);
      f[0][u][i + j + (p < m)] = max(f[0][u][i + j + (p < m)],
                                     f[0][son[u][0]][i] + f[0][son[u][1]][j]);
      f[1][u][i + j + (p < m)] = min(f[1][u][i + j + (p < m)],
                                     f[1][son[u][0]][i] + f[1][son[u][1]][j]);
    }
}
signed main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  tot = pre = 1;
  memset(f[0], -0x3f, sizeof f[0]);
  memset(f[1], 0x3f, sizeof f[1]);
  for (int i = 1; i <= n; i++) {
    if (s[i] == '(' || s[i] == '?')
      son[pre][son[pre][0] ? 1 : 0] = ++tot, fa[tot] = pre, pre = tot;
    else if (s[i] == ')')
      pre = fa[pre];
    else
      f[0][tot][0] = f[1][tot][0] = s[i] - '0', pre = fa[pre];
  }
  p = read();
  m = read();
  k = min(p, m);
  dfs(1);
  printf("%d\n", f[0][1][k]);
}
