#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 19260817;
const long long mod2 = 19660813;
char s[10005];
int p;
int m;
int mn;
int n;
int cnt;
int cur;
int father[10005];
int dp[10005][105][2];
int son[10005][2];
void dfs(int rt) {
  if (son[rt][0]) dfs(son[rt][0]);
  if (son[rt][1]) dfs(son[rt][1]);
  for (int i = 0; i <= mn; ++i) {
    for (int j = 0; j + i <= mn; ++j) {
      dp[rt][i + j + (p <= m)][0] =
          max(dp[rt][i + j + (p <= m)][0],
              dp[son[rt][0]][i][0] + dp[son[rt][1]][j][0]);
      dp[rt][i + j + (p > m)][0] =
          max(dp[rt][i + j + (p > m)][0],
              dp[son[rt][0]][i][0] - dp[son[rt][1]][j][1]);
      dp[rt][i + j + (p <= m)][1] =
          min(dp[rt][i + j + (p <= m)][1],
              dp[son[rt][0]][i][1] + dp[son[rt][1]][j][1]);
      dp[rt][i + j + (p > m)][1] =
          min(dp[rt][i + j + (p > m)][1],
              dp[son[rt][0]][i][1] - dp[son[rt][1]][j][0]);
    }
  }
}
int main() {
  for (int i = 0; i < 10005; ++i)
    for (int j = 0; j < 105; ++j)
      dp[i][j][0] = -1000000000, dp[i][j][1] = 1000000000;
  scanf("%s", s + 1);
  n = (int)strlen(s + 1);
  scanf("%d %d", &p, &m);
  mn = min(p, m);
  cur = 1;
  cnt = 1;
  for (int i = 1; i <= n; ++i) {
    if (s[i] == '(' || s[i] == '?') {
      ++cnt;
      father[cnt] = cur;
      son[cur][son[cur][0] ? 1 : 0] = cnt;
      cur = cnt;
    } else if (s[i] == ')') {
      cur = father[cur];
    } else {
      dp[cur][0][0] = dp[cur][0][1] = s[i] - '0';
      cur = father[cur];
    }
  }
  dfs(1);
  printf("%d\n", dp[1][mn][0]);
  return 0;
}
