#include <bits/stdc++.h>
using namespace std;
int tp, pl, mi, m, sm, bg, t, stk[10005], go[10005], mx[10005][105],
    mn[10005][105];
char s[10005];
int dfs(int l, int r) {
  int x = ++t;
  if (l == r) {
    mx[x][0] = mn[x][0] = s[l] - '0';
    return x;
  }
  int xx = s[l + 1] == '(' ? go[l + 1] + 1 : l + 2;
  int ls = dfs(l + 1, xx - 1), rs = dfs(xx + 1, r - 1);
  for (int j = sm; j <= m; j++)
    for (int k = 0; k + sm <= j; k++) {
      mx[x][j] = max(mx[x][j], mx[ls][k] + mx[rs][j - sm - k]);
      mn[x][j] = min(mn[x][j], mn[ls][k] + mn[rs][j - sm - k]);
    }
  for (int j = bg; j <= m; j++)
    for (int k = 0; k + bg <= j; k++) {
      mx[x][j] = max(mx[x][j], mx[ls][k] - mn[rs][j - bg - k]);
      mn[x][j] = min(mn[x][j], mn[ls][k] - mx[rs][j - bg - k]);
    }
  return x;
}
int main() {
  scanf("%s", s + 1);
  scanf("%d%d", &pl, &mi);
  sm = pl < mi;
  bg = sm ^ 1;
  m = min(pl, mi);
  for (int i = strlen(s + 1); i; i--)
    if (s[i] == ')')
      stk[++tp] = i;
    else if (s[i] == '(')
      go[i] = stk[tp--];
  for (int i = 1; i < 10005; i++)
    for (int j = 0; j <= m; j++) mx[i][j] = -1e9, mn[i][j] = 1e9;
  int res = dfs(1, strlen(s + 1));
  printf("%d\n", mx[res][m]);
}
