#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;
int node_id = 0;
bool solved[5000][5000];
pair<int, int> dp[5000][5000];
struct node {
  char symbol;
  int id;
  int cnt;
  int minval, maxval;
  node *left, *right;
  node(char symbol, int id)
      : symbol(symbol), id(id), cnt(0), left(nullptr), right(nullptr) {}
};
node *parse(string expr) {
  if (expr.length() == 1) {
    assert('0' <= expr[0] and expr[0] <= '9');
    node *nd = new node(expr[0], node_id++);
    return nd;
  }
  int n = expr.length();
  assert(expr[0] == '(');
  assert(expr[n - 1] == ')');
  int depth = 0;
  node *nd;
  for (int i = 1; i < n - 1; i++) {
    if (expr[i] == '(')
      depth++;
    else if (expr[i] == ')')
      depth--;
    else if (expr[i] == '?' and depth == 0) {
      string L = expr.substr(1, i - 1);
      string R = expr.substr(i + 1, n - i - 2);
      nd = new node(expr[i], node_id++);
      nd->left = parse(L);
      nd->right = parse(R);
      nd->cnt = nd->left->cnt + nd->right->cnt + 1;
      break;
    }
  }
  return nd;
}
pair<int, int> solve(node *nd, int P, int M) {
  if (nd->symbol != '?') {
    return {nd->symbol - '0', nd->symbol - '0'};
  }
  int maxval = -INF;
  int minval = INF;
  assert(P + M == nd->cnt);
  if (solved[nd->id][P]) return dp[nd->id][P];
  if (P > 0) {
    for (int pl =
             ((0) > (P - 1 - nd->right->cnt) ? (0) : (P - 1 - nd->right->cnt));
         pl <= ((P - 1) < (nd->left->cnt) ? (P - 1) : (nd->left->cnt)); pl++) {
      int ml = nd->left->cnt - pl;
      int pr = P - 1 - pl;
      int mr = nd->right->cnt - pr;
      assert(mr >= 0);
      assert(mr + ml == M);
      int minR, maxR, minL, maxL;
      tie(minL, maxL) = solve(nd->left, pl, ml);
      tie(minR, maxR) = solve(nd->right, pr, mr);
      maxval = ((maxval) > (maxL + maxR) ? (maxval) : (maxL + maxR));
      minval = ((minval) < (minL + minR) ? (minval) : (minL + minR));
    }
  }
  if (M > 0) {
    for (int pl = ((0) > (P - nd->right->cnt) ? (0) : (P - nd->right->cnt));
         pl <= ((P) < (nd->left->cnt) ? (P) : (nd->left->cnt)); pl++) {
      int ml = nd->left->cnt - pl;
      int pr = P - pl;
      int mr = nd->right->cnt - pr;
      assert(mr >= 0);
      assert(mr + ml == M - 1);
      int minR, maxR, minL, maxL;
      tie(minL, maxL) = solve(nd->left, pl, ml);
      tie(minR, maxR) = solve(nd->right, pr, mr);
      maxval = ((maxval) > (maxL - minR) ? (maxval) : (maxL - minR));
      minval = ((minval) < (minL - maxR) ? (minval) : (minL - maxR));
    }
  }
  solved[nd->id][P] = true;
  dp[nd->id][P] = {minval, maxval};
  return {minval, maxval};
}
int32_t main() {
  string expr;
  cin >> expr;
  int P_tot, M_tot;
  cin >> P_tot >> M_tot;
  node *root = parse(expr);
  memset(solved, false, sizeof(solved));
  ;
  int minval, maxval;
  tie(minval, maxval) = solve(root, P_tot, M_tot);
  cout << maxval << endl;
  return 0;
}
