#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
int tr[10005][2], fa[10005], dp[2][10005][105], minn;
int p, m;
void dfs(int id) {
  if (!tr[id][0]) return;
  int l = tr[id][0], r = tr[id][1];
  dfs(l);
  dfs(r);
  for (int i = 0; i <= minn; i++) {
    for (int j = 0; j + i <= minn; j++) {
      dp[0][id][i + j + (p < m)] =
          max(dp[0][id][i + j + (p < m)], dp[0][l][i] + dp[0][r][j]);
      dp[0][id][i + j + (p >= m)] =
          max(dp[0][id][i + j + (p >= m)], dp[0][l][i] - dp[1][r][j]);
      dp[1][id][i + j + (p < m)] =
          min(dp[1][id][i + j + (p < m)], dp[1][l][i] + dp[1][r][j]);
      dp[1][id][i + j + (p >= m)] =
          min(dp[1][id][i + j + (p >= m)], dp[1][l][i] - dp[0][r][j]);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  char s[10005];
  cin >> s + 1;
  cin >> p >> m;
  memset(dp[0], -63, sizeof(dp[0]));
  memset(dp[1], 63, sizeof(dp[1]));
  minn = min(p, m);
  int size = 1, pre = size;
  for (int i = 1; i <= strlen(s + 1); 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
      dp[0][size][0] = dp[1][size][0] = s[i] - '0', pre = fa[pre];
  }
  dfs(1);
  cout << dp[0][1][minn] << endl;
  return 0;
}
