#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
const int N = 10 * 1000 + 7;
int test;
int a, b, n;
string s;
int cou = 1;
int dp[N][107][2];
int L[N], R[N];
void zrob(int l, int r, int v) {
  for (int i = 0; i <= (100); ++i) {
    dp[v][i][0] = -1000000007;
    dp[v][i][1] = 1000000007;
  }
  if (l == r) {
    dp[v][0][0] = dp[v][0][1] = s[l] - '0';
    return;
  }
  int ile = 0;
  for (int i = l; i <= (r); ++i) {
    ile += s[i] == '(';
    ile -= s[i] == ')';
    if (ile == 1 && s[i] == '?') {
      L[v] = ++cou;
      R[v] = ++cou;
      zrob(l + 1, i - 1, L[v]);
      zrob(i + 1, r - 1, R[v]);
      break;
    }
  }
  if (a <= 100)
    for (int i = 0; i <= (a); ++i) {
      for (int j = 0; j <= (i); ++j) {
        dp[v][i + 1][0] =
            max(dp[v][i + 1][0], dp[L[v]][j][0] + dp[R[v]][i - j][0]);
        dp[v][i][0] = max(dp[v][i][0], dp[L[v]][j][0] - dp[R[v]][i - j][1]);
        dp[v][i + 1][1] =
            min(dp[v][i + 1][1], dp[L[v]][j][1] + dp[R[v]][i - j][1]);
        dp[v][i][1] = min(dp[v][i][1], dp[L[v]][j][1] - dp[R[v]][i - j][0]);
      }
    }
  else
    for (int i = 0; i <= (b); ++i) {
      for (int j = 0; j <= (i); ++j) {
        dp[v][i][0] = max(dp[v][i][0], dp[L[v]][j][0] + dp[R[v]][i - j][0]);
        dp[v][i + 1][0] =
            max(dp[v][i + 1][0], dp[L[v]][j][0] - dp[R[v]][i - j][1]);
        dp[v][i][1] = min(dp[v][i][1], dp[L[v]][j][1] + dp[R[v]][i - j][1]);
        dp[v][i + 1][1] =
            min(dp[v][i + 1][1], dp[L[v]][j][1] - dp[R[v]][i - j][0]);
      }
    }
}
void solve() {
  cin >> s;
  cin >> a >> b;
  n = s.size();
  if (n == 1) {
    cout << s << '\n';
    return;
  }
  s = '#' + s;
  zrob(1, n, cou);
  if (a <= 100)
    cout << dp[1][a][0];
  else
    cout << dp[1][b][0];
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
