#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7, maxn = 10005, ln = 17, maxm = 5005;
inline void S(int& n) {
  n = 0;
  int ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  }
  n = n * sign;
}
const int shift = 30, etf = mod - 1, LIM = (int)1e9;
const long long int inf = (long long int)1e18 + 1;
const double PI = (double)3.141592653589793238, EPSILON = 1e-10;
string EXPR;
int P, N;
int pairing[10001], counting[10001];
int dp[10001][101][2];
bool status[10001][101][2];
int findPos(int pos) {
  int cnt = 0;
  int signc = 0;
  int tot = counting[pos];
  pos++;
  while (1) {
    if (EXPR[pos] == '(') {
      cnt++;
    } else if (EXPR[pos] == ')') {
      cnt--;
    }
    if (EXPR[pos] == '?') {
      signc++;
      if (cnt == 0) {
        counting[pairing[pos - 1]] = signc - 1;
        counting[pos + 1] = tot - signc;
        return pos;
      }
    }
    pos++;
  }
}
int findMaxVal(int pos, int signcnt, int minormax, int signtype) {
  if (EXPR[pos] >= '0' && EXPR[pos] <= '9') {
    return EXPR[pos] - '0';
  }
  int& res = dp[pos][signcnt][minormax];
  if (status[pos][signcnt][minormax] == false) {
    status[pos][signcnt][minormax] = true;
    if (minormax == 0)
      res = INT_MIN;
    else
      res = INT_MAX;
    int x = findPos(pos);
    int l = pairing[x - 1];
    int r = x + 1;
    int lc = counting[l];
    int rc = counting[r];
    if (signcnt) {
      int remsigns = signcnt - 1;
      for (int i = max(0, remsigns - rc); i < min(remsigns, lc) + 1; i++) {
        if (signtype == 0) {
          if (minormax == 0)
            res = max(res, findMaxVal(l, i, 0, signtype) +
                               findMaxVal(r, remsigns - i, 0, signtype));
          else
            res = min(res, findMaxVal(l, i, 1, signtype) +
                               findMaxVal(r, remsigns - i, 1, signtype));
        } else {
          if (minormax == 0)
            res = max(res, findMaxVal(l, i, 0, signtype) -
                               findMaxVal(r, remsigns - i, 1, signtype));
          else
            res = min(res, findMaxVal(l, i, 1, signtype) -
                               findMaxVal(r, remsigns - i, 0, signtype));
        }
      }
    }
    if (signcnt <= lc + rc) {
      for (int i = max(0, signcnt - rc); i < min(signcnt, lc) + 1; i++) {
        if (signtype == 0) {
          if (minormax == 0)
            res = max(res, findMaxVal(l, i, 0, signtype) -
                               findMaxVal(r, signcnt - i, 1, signtype));
          else
            res = min(res, findMaxVal(l, i, 1, signtype) -
                               findMaxVal(r, signcnt - i, 0, signtype));
        } else {
          if (minormax == 0)
            res = max(res, findMaxVal(l, i, 0, signtype) +
                               findMaxVal(r, signcnt - i, 0, signtype));
          else
            res = min(res, findMaxVal(l, i, 1, signtype) +
                               findMaxVal(r, signcnt - i, 1, signtype));
        }
      }
    }
  }
  return res;
}
void pre() {
  int cnt = 0;
  stack<int> stk;
  int len = EXPR.length();
  for (int i = 0; i < len; i++) {
    if (EXPR[i] == '(')
      stk.push(i);
    else if (EXPR[i] == ')') {
      int tt = stk.top();
      stk.pop();
      pairing[tt] = tt;
      pairing[i] = tt;
    } else if (EXPR[i] >= '0' && EXPR[i] <= '9')
      pairing[i] = i;
    if (EXPR[i] == '?') cnt++;
  }
  counting[0] = cnt;
}
void _debug(int n, int m, int flag) {
  if (flag == 0)
    printf("max array: \n");
  else
    printf("min array: \n");
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      printf("%d ", dp[i][j][flag]);
    }
    printf("\n");
  }
}
int main() {
  cin >> EXPR >> P >> N;
  pre();
  if (P <= N)
    cout << findMaxVal(0, P, 0, 0) << endl;
  else
    cout << findMaxVal(0, N, 0, 1) << endl;
  return 0;
}
