#include <bits/stdc++.h>
using namespace std;
string E;
int P, M, n;
vector<int> vtx;
pair<int, int> to[400004];
int val[400004];
vector<int> wat;
struct dp {
  int num, pl, ms;
};
bool operator<(dp u, dp v) {
  if (u.num != v.num) return u.num < v.num;
  if (u.pl != v.pl) return u.pl < v.pl;
  return u.ms < v.ms;
}
map<dp, pair<int, int> > mp;
map<dp, bool> used;
void get_E() {
  string tmp = "";
  for (int i = 0; i < E.size(); i++) {
    if (E[i] >= '1' && E[i] <= '9') {
      tmp += "(";
      tmp += E[i];
      tmp += ")";
    } else
      tmp += E[i];
  }
  E = tmp;
  n = E.size();
}
int create(int l, int r) {
  if (l > r) return -1;
  if (l + 2 == r) {
    vtx.push_back(-1);
    wat.push_back(0);
    val[vtx.size() - 1] = E[l + 1] - '0';
    to[vtx.size() - 1] = make_pair(0, 0);
    return vtx.size() - 1;
  }
  int tmp = 0, pos = -1, cnt = 0;
  for (int i = l + 1; i < r; i++) {
    if (E[i] == '(')
      tmp++;
    else if (E[i] == ')')
      tmp--;
    if (!tmp && pos == -1) {
      pos = i;
    }
    cnt += (E[i] == '?');
  }
  vtx.push_back(pos + 1);
  wat.push_back(cnt);
  int num = vtx.size() - 1;
  to[num] = make_pair(create(l + 1, pos), create(pos + 2, r - 1));
  return num;
}
pair<int, int> rec(int num, int p, int m) {
  if (vtx[num] == -1) return make_pair(val[num], val[num]);
  dp V = (dp){num, p, m};
  if (used[V]) return mp[V];
  int mt = 1e9, Mt = -1e9, ln = to[num].first, rn = to[num].second;
  for (int i = 0; i <= min(p - 1, wat[ln]); i++) {
    int pl = i;
    int ml = wat[ln] - pl;
    int pr = p - pl - 1;
    int mr = m - ml;
    if (pr < 0 || mr < 0 || pl < 0 || ml < 0) continue;
    pair<int, int> dpLeft = rec(ln, pl, ml);
    pair<int, int> dpRight = rec(rn, pr, mr);
    int lm = dpLeft.second;
    int lM = dpLeft.first;
    int rm = dpRight.second;
    int rM = dpRight.first;
    mt = min(mt, min(lm + rm, min(lm + rM, min(lM + rm, lM + rM))));
    Mt = max(Mt, max(lm + rm, max(lm + rM, max(lM + rm, lM + rM))));
  }
  for (int i = 0; i <= min(m - 1, wat[ln]); i++) {
    int ml = i;
    int pl = wat[ln] - ml;
    int pr = p - pl;
    int mr = m - ml - 1;
    if (pr < 0 || mr < 0 || pl < 0 || ml < 0) continue;
    pair<int, int> dpLeft = rec(ln, pl, ml);
    pair<int, int> dpRight = rec(rn, pr, mr);
    int lm = dpLeft.second;
    int lM = dpLeft.first;
    int rm = dpRight.second;
    int rM = dpRight.first;
    mt = min(mt, min(lm - rm, min(lm - rM, min(lM - rm, lM - rM))));
    Mt = max(Mt, max(lm - rm, max(lm - rM, max(lM - rm, lM - rM))));
  }
  used[V] = 1;
  return mp[V] = make_pair(Mt, mt);
}
int main() {
  cin >> E >> P >> M;
  get_E();
  create(0, n - 1);
  cout << rec(0, P, M).first;
  return 0;
}
