#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e4 + 5;
const long long oo = 1e9 + 7;
struct node {
  long long l, r, number_of_signs;
  bool leaf;
  long long lef, rig;
} it[4 * MAXN];
vector<pair<long long, long long> > v;
string s;
long long P, M, peak = 0;
void build_tree(long long i) {
  it[i].l = v[peak].first;
  it[i].r = v[peak].second;
  if (v[peak].first == v[peak].second) {
    it[i].leaf = true;
    it[i].number_of_signs = 0;
    return;
  }
  peak++;
  it[i].lef = peak;
  build_tree(peak);
  peak++;
  it[i].rig = peak;
  build_tree(peak);
  it[i].leaf = false;
  it[i].number_of_signs =
      it[it[i].lef].number_of_signs + it[it[i].rig].number_of_signs + 1;
}
long long f[4 * MAXN][105][2];
long long ch[4 * MAXN][105][2];
long long dp(long long i, long long nus, long long type) {
  if (ch[i][nus][type] > 0) return f[i][nus][type];
  if (nus > it[i].number_of_signs || nus < 0) {
    if (type == 1)
      return -oo;
    else
      return oo;
  }
  if (it[i].leaf == true) return s[it[i].l] - '0';
  ch[i][nus][type] = 1;
  if (type == 1) {
    long long res = -oo;
    for (long long j = 0; j <= nus; ++j) {
      if (j > it[it[i].lef].number_of_signs) break;
      res = max(res, dp(it[i].lef, j, 1) +
                         dp(it[i].rig, nus - j - (P > M ? 0 : 1), 1));
      res = max(res, dp(it[i].lef, j, 1) -
                         dp(it[i].rig, nus - j - (P > M ? 1 : 0), 0));
    }
    return f[i][nus][1] = res;
  }
  long long res = oo;
  for (long long j = 0; j <= nus; ++j) {
    if (j > it[it[i].lef].number_of_signs) break;
    res = min(
        res, dp(it[i].lef, j, 0) + dp(it[i].rig, nus - j - (P > M ? 0 : 1), 0));
    res = min(
        res, dp(it[i].lef, j, 0) - dp(it[i].rig, nus - j - (P > M ? 1 : 0), 1));
  }
  return f[i][nus][0] = res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  std::stack<long long> st;
  for (long long i = 0; i < s.size(); ++i) {
    if (s[i] == '(') st.push(i);
    if (s[i] >= '0' && s[i] <= '9')
      v.push_back(pair<long long, long long>(i, i));
    if (s[i] == ')') {
      v.push_back(pair<long long, long long>(st.top(), i));
      st.pop();
    }
  }
  sort(v.begin(), v.end());
  build_tree(0);
  cin >> P >> M;
  memset(ch, 0, sizeof ch);
  cout << dp(0, min(M, P), 1);
}
