#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 10005;
int n, m, p, k, pre, dp[2][M][N], fa[M], son[M][2], tot;
char s[M];
void dfs(int x) {
  if (!x) return;
  dfs(son[x][0]);
  dfs(son[x][1]);
  for (int i = 0; i <= k; i++)
    for (int j = 0; j <= k - i; j++) {
      dp[0][x][i + j + (p >= m)] =
          max(dp[0][x][i + j + (p >= m)],
              dp[0][son[x][0]][i] - dp[1][son[x][1]][j]);
      dp[1][x][i + j + (p >= m)] =
          min(dp[1][x][i + j + (p >= m)],
              dp[1][son[x][0]][i] - dp[0][son[x][1]][j]);
      dp[0][x][i + j + (p < m)] = max(
          dp[0][x][i + j + (p < m)], dp[0][son[x][0]][i] + dp[0][son[x][1]][j]);
      dp[1][x][i + j + (p < m)] = min(
          dp[1][x][i + j + (p < m)], dp[1][son[x][0]][i] + dp[1][son[x][1]][j]);
    }
}
int main() {
  ios ::sync_with_stdio(0);
  cin >> s + 1;
  n = strlen(s + 1);
  tot = pre = 1;
  memset(dp[0], -0x3f, sizeof dp[0]);
  memset(dp[1], 0x3f, sizeof dp[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
      dp[0][tot][0] = dp[1][tot][0] = s[i] - '0', pre = fa[pre];
  }
  cin >> p >> m;
  k = min(p, m);
  dfs(1);
  cout << dp[0][1][k];
  return 0;
}
