#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 5;
const long long INF = 2e8;
int node[MAXN][3];
int pos, neg;
int cnt;
long long dp[MAXN][105][2];
bool isneg = false;
int alloc(char n, int left, int right) {
  node[cnt][0] = n;
  node[cnt][1] = left;
  node[cnt][2] = right;
  cnt++;
  return cnt - 1;
}
void parse(string s) {
  stack<int> st;
  for (char c : s) {
    if (c == ')') {
      int r = st.top();
      st.pop();
      int l = st.top();
      st.pop();
      st.push(alloc('?', l, r));
    } else if (c != '(' && c != '?') {
      st.push(alloc(c, -1, -1));
    }
  }
}
void init() {
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < 105; j++) {
      dp[i][j][0] = -INF;
      dp[i][j][1] = INF;
    }
}
void dfs(int n) {
  if (node[n][0] != '?') {
    dp[n][0][0] = dp[n][0][1] = node[n][0] - '0';
    return;
  }
  int lc = node[n][1];
  dfs(lc);
  int rc = node[n][2];
  dfs(rc);
  if (isneg)
    for (int x = 0; x <= 100; x++) {
      for (int lx = 0; lx <= x; lx++) {
        dp[n][x][0] = max(dp[n][x][0], dp[lc][lx][0] + dp[rc][x - lx][0]);
        dp[n][x][1] = min(dp[n][x][1], dp[lc][lx][1] + dp[rc][x - lx][1]);
      }
      for (int lx = 0; lx <= x - 1; lx++) {
        dp[n][x][0] = max(dp[n][x][0], dp[lc][lx][0] - dp[rc][x - lx - 1][1]);
        dp[n][x][1] = min(dp[n][x][1], dp[lc][lx][1] - dp[rc][x - lx - 1][0]);
      }
    }
  else
    for (int x = 0; x <= 100; x++) {
      for (int lx = 0; lx <= x; lx++) {
        dp[n][x][0] = max(dp[n][x][0], dp[lc][lx][0] - dp[rc][x - lx][1]);
        dp[n][x][1] = min(dp[n][x][1], dp[lc][lx][1] - dp[rc][x - lx][0]);
      }
      for (int lx = 0; lx <= x - 1; lx++) {
        dp[n][x][0] = max(dp[n][x][0], dp[lc][lx][0] + dp[rc][x - lx - 1][0]);
        dp[n][x][1] = min(dp[n][x][1], dp[lc][lx][1] + dp[rc][x - lx - 1][1]);
      }
    }
}
int main() {
  init();
  string s;
  cin >> s;
  cin >> pos >> neg;
  if (neg < pos) isneg = true;
  parse(s);
  dfs(--cnt);
  cout << dp[cnt][min(neg, pos)][0] << endl;
  return 0;
}
