#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9;
const long long K = 101;
pair<vector<long long>, vector<long long> > solve(string s, long long l,
                                                  long long r) {
  vector<long long> Mn(K), Mx(K);
  for (long long i = 0; i < K; i++) {
    Mn[i] = INF;
    Mx[i] = -INF;
  }
  if (r == l) {
    Mn[0] = s[l] - '0';
    Mx[0] = s[l] - '0';
    return make_pair(Mn, Mx);
  }
  long long B = 0, ind;
  for (long long i = l; i <= r; i++) {
    if (s[i] == '(') B++;
    if (s[i] == ')') B--;
    if (s[i] == '?' && B == 1) {
      ind = i;
      break;
    }
  }
  pair<vector<long long>, vector<long long> > p1 = solve(s, l + 1, ind - 1);
  pair<vector<long long>, vector<long long> > p2 = solve(s, ind + 1, r - 1);
  for (long long i = 0; i < K; i++) {
    for (long long j = 0; j + i < K; j++) {
      if (j + i + 1 < K) {
        Mx[i + j + 1] = max(Mx[i + j + 1], p1.second[i] + p2.second[j]);
        Mn[i + j + 1] = min(Mn[i + j + 1], p1.first[i] + p2.first[j]);
      }
      Mx[i + j] = max(Mx[i + j], p1.second[i] - p2.first[j]);
      Mn[i + j] = min(Mn[i + j], p1.first[i] - p2.second[j]);
    }
  }
  return make_pair(Mn, Mx);
}
pair<vector<long long>, vector<long long> > Solve(string s, long long l,
                                                  long long r) {
  vector<long long> Mn(K), Mx(K);
  for (long long i = 0; i < K; i++) {
    Mn[i] = INF;
    Mx[i] = -INF;
  }
  if (r == l) {
    Mn[0] = s[l] - '0';
    Mx[0] = s[l] - '0';
    return make_pair(Mn, Mx);
  }
  long long B = 0, ind;
  for (long long i = l; i <= r; i++) {
    if (s[i] == '(') B++;
    if (s[i] == ')') B--;
    if (s[i] == '?' && B == 1) {
      ind = i;
      break;
    }
  }
  pair<vector<long long>, vector<long long> > p1 = Solve(s, l + 1, ind - 1);
  pair<vector<long long>, vector<long long> > p2 = Solve(s, ind + 1, r - 1);
  for (long long i = 0; i < K; i++) {
    for (long long j = 0; j + i < K; j++) {
      Mx[i + j] = max(Mx[i + j], p1.second[i] + p2.second[j]);
      Mn[i + j] = min(Mn[i + j], p1.first[i] + p2.first[j]);
      if (i + j + 1 < K) {
        Mx[i + j + 1] = max(Mx[i + j + 1], p1.second[i] - p2.first[j]);
        Mn[i + j + 1] = min(Mn[i + j + 1], p1.first[i] - p2.second[j]);
      }
    }
  }
  return make_pair(Mn, Mx);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long p, m;
  cin >> p >> m;
  if (m <= 100) {
    pair<vector<long long>, vector<long long> > ans = Solve(s, 0, s.size() - 1);
    cout << ans.second[m] << endl;
    return 0;
  }
  if (p <= 100) {
    pair<vector<long long>, vector<long long> > ans = solve(s, 0, s.size() - 1);
    cout << ans.second[p] << endl;
  }
  return 0;
}
