#include <bits/stdc++.h>
const bool DEBUG = false;
using namespace std;
const long long maxn = 1e4 + 100;
const int INF = 1e9;
const int NIS = 1e9 + 1;
const int K = 40;
int p, m, n, gand, M, P = 1, dp[maxn];
string s;
bool flag;
int mx[maxn][106], mn[maxn][106];
inline int cnt(int l, int r) {
  if (l == 0) return dp[r];
  return dp[r] - dp[l - 1];
}
inline int MX(int l, int r, int p, int m);
inline int MN(int l, int r, int p, int m);
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s;
  cin >> p >> m;
  if (m <= p) swap(P, M);
  n = s.size();
  if (n == 1) return cout << s[0] << endl, 0;
  for (int i = 1; i < n; i++) dp[i] = dp[i - 1] + (s[i] == '?');
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 101; j++) mx[i][j] = mn[i][j] = NIS;
  cout << MX(0, n - 1, p, m) << endl;
  return 0;
}
inline int MX(int l, int r, int p, int m) {
  int flag = 0, ans = -INF, d = 0;
  vector<int> v;
  vector<pair<int, int> > B;
  if (P and mx[l][p] != NIS) return mx[l][p];
  if (M and mx[l][m] != NIS) return mx[l][m];
  if (r - l == 4) {
    if (p == 1)
      ans = (s[l + 1] - '0') + (s[r - 1] - '0');
    else
      ans = (s[l + 1] - '0') - (s[r - 1] - '0');
    if (P) return mx[l][p] = ans;
    return mx[l][m] = ans;
  }
  for (int i = l + 1; i <= r - 1; i++) {
    if (s[i] == '(')
      v.push_back(i);
    else if (s[i] == ')') {
      int x = v.back();
      if (v.size() == 1) B.push_back({x, i});
      v.pop_back();
    } else if (s[i] >= '0' and s[i] <= '9' and v.size() == 0) {
      if (i == l + 1)
        flag = 1;
      else
        flag = 2;
      d = s[i] - '0';
    }
  }
  if (flag) {
    int st = B[0].first, en = B[0].second;
    if (p) ans = max(ans, d + MX(st, en, p - 1, m));
    if (m) {
      if (flag == 1)
        ans = max(ans, d - MN(st, en, p, m - 1));
      else
        ans = max(ans, MX(st, en, p, m - 1) - d);
    }
  } else {
    int st1 = B[0].first, en1 = B[0].second;
    int st2 = B[1].first, en2 = B[1].second;
    int t1 = cnt(st1, en1);
    int t2 = cnt(st2, en2);
    if (p) {
      p--;
      if (p <= m) {
        for (int i = 0; i <= min(t1, p); i++) {
          if (p - i >= 0 and t2 - (p - i) >= 0)
            ans = max(ans, MX(st1, en1, i, t1 - i) +
                               MX(st2, en2, p - i, t2 - (p - i)));
        }
      } else {
        for (int i = 0; i <= min(t1, m); i++) {
          if (m - i >= 0 and t2 - (m - i) >= 0)
            ans = max(ans, MX(st1, en1, t1 - i, i) +
                               MX(st2, en2, t2 - (m - i), m - i));
        }
      }
      p++;
    }
    if (m) {
      m--;
      if (p <= m) {
        for (int i = 0; i <= min(t1, p); i++) {
          if (p - i >= 0 and t2 - (p - i) >= 0)
            ans = max(ans, MX(st1, en1, i, t1 - i) -
                               MN(st2, en2, p - i, t2 - (p - i)));
        }
      } else {
        for (int i = 0; i <= min(t1, m); i++) {
          if (m - i >= 0 and t2 - (m - i) >= 0)
            ans = max(ans, MX(st1, en1, t1 - i, i) -
                               MN(st2, en2, t2 - (m - i), m - i));
        }
      }
      m++;
    }
  }
  if (P) return mx[l][p] = ans;
  return mx[l][m] = ans;
}
inline int MN(int l, int r, int p, int m) {
  int flag = 0, ans = +INF, d = 0;
  vector<int> v;
  vector<pair<int, int> > B;
  if (P and mn[l][p] != NIS) return mn[l][p];
  if (M and mn[l][m] != NIS) return mn[l][m];
  if (r - l == 4) {
    if (p == 1)
      ans = (s[l + 1] - '0') + (s[r - 1] - '0');
    else
      ans = (s[l + 1] - '0') - (s[r - 1] - '0');
    if (P) return mn[l][p] = ans;
    return mn[l][m] = ans;
  }
  for (int i = l + 1; i <= r - 1; i++) {
    if (s[i] == '(')
      v.push_back(i);
    else if (s[i] == ')') {
      int x = v.back();
      if (v.size() == 1) B.push_back({x, i});
      v.pop_back();
    } else if (s[i] >= '0' and s[i] <= '9' and v.size() == 0) {
      if (i == l + 1)
        flag = 1;
      else
        flag = 2;
      d = s[i] - '0';
    }
  }
  if (flag) {
    int st = B[0].first, en = B[0].second;
    if (p) ans = min(ans, d + MN(st, en, p - 1, m));
    if (m) {
      if (flag == 1)
        ans = min(ans, d - MX(st, en, p, m - 1));
      else
        ans = min(ans, MN(st, en, p, m - 1) - d);
    }
  } else {
    int st1 = B[0].first, en1 = B[0].second;
    int st2 = B[1].first, en2 = B[1].second;
    int t1 = cnt(st1, en1);
    int t2 = cnt(st2, en2);
    if (p) {
      p--;
      if (p <= m) {
        for (int i = 0; i <= min(t1, p); i++) {
          if (p - i >= 0 and t2 - (p - i) >= 0)
            ans = min(ans, MN(st1, en1, i, t1 - i) +
                               MN(st2, en2, p - i, t2 - (p - i)));
        }
      } else {
        for (int i = 0; i <= min(t1, m); i++) {
          if (m - i >= 0 and t2 - (m - i) >= 0)
            ans = min(ans, MN(st1, en1, t1 - i, i) +
                               MN(st2, en2, t2 - (m - i), m - i));
        }
      }
      p++;
    }
    if (m) {
      m--;
      if (p <= m) {
        for (int i = 0; i <= min(t1, p); i++) {
          if (p - i >= 0 and t2 - (p - i) >= 0)
            ans = min(ans, MN(st1, en1, i, t1 - i) -
                               MX(st2, en2, p - i, t2 - (p - i)));
        }
      } else {
        for (int i = 0; i <= min(t1, m); i++) {
          if (m - i >= 0 and t2 - (m - i) >= 0)
            ans = min(ans, MN(st1, en1, t1 - i, i) -
                               MX(st2, en2, t2 - (m - i), m - i));
        }
      }
      m++;
    }
  }
  if (P) return mn[l][p] = ans;
  return mn[l][m] = ans;
}
