#include <bits/stdc++.h>
using namespace std;
int inf = 1e9 + 7;
bool t;
vector<vector<pair<int, int> > > ans;
vector<int> op;
int mn(int a, int b) {
  if (t == 1)
    return a - b;
  else
    return a + b;
}
int mx(int a, int b) {
  if (t == 0)
    return a - b;
  else
    return a + b;
}
void solve() {
  vector<pair<int, int> > a = ans.back();
  ans.pop_back();
  vector<pair<int, int> > b = ans.back();
  ans.pop_back();
  vector<pair<int, int> > c(101, make_pair(-inf, inf));
  for (int i = 0; i < (101); ++i) {
    for (int j = 0; j < (101); ++j) {
      if (i + j > 100 || b[i].first == -inf || a[j].first == -inf) continue;
      c[i + j].second = min(c[i + j].second, mx(b[i].second, a[j].first));
      if (i + j < 100)
        c[i + j + 1].second =
            min(c[i + j + 1].second, mn(b[i].second, a[j].first));
      c[i + j].first = max(c[i + j].first, mx(b[i].second, a[j].first));
      if (i + j < 100)
        c[i + j + 1].first =
            max(c[i + j + 1].first, mn(b[i].second, a[j].first));
      c[i + j].second = min(c[i + j].second, mx(b[i].first, a[j].second));
      if (i + j < 100)
        c[i + j + 1].second =
            min(c[i + j + 1].second, mn(b[i].first, a[j].second));
      c[i + j].first = max(c[i + j].first, mx(b[i].first, a[j].second));
      if (i + j < 100)
        c[i + j + 1].first =
            max(c[i + j + 1].first, mn(b[i].first, a[j].second));
      c[i + j].second = min(c[i + j].second, mx(b[i].second, a[j].second));
      if (i + j < 100)
        c[i + j + 1].second =
            min(c[i + j + 1].second, mn(b[i].second, a[j].second));
      c[i + j].first = max(c[i + j].first, mx(b[i].second, a[j].second));
      if (i + j < 100)
        c[i + j + 1].first =
            max(c[i + j + 1].first, mn(b[i].second, a[j].second));
      c[i + j].second = min(c[i + j].second, mx(b[i].first, a[j].first));
      if (i + j < 100)
        c[i + j + 1].second =
            min(c[i + j + 1].second, mn(b[i].first, a[j].first));
      c[i + j].first = max(c[i + j].first, mx(b[i].first, a[j].first));
      if (i + j < 100)
        c[i + j + 1].first =
            max(c[i + j + 1].first, mn(b[i].first, a[j].first));
    }
  }
  ans.push_back(c);
  op.pop_back();
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  string s;
  cin >> s;
  int p, m;
  cin >> p >> m;
  t = (p > m);
  for (auto& i : s) {
    if (i == '(')
      op.push_back(0);
    else if (i == '?') {
      op.push_back(1);
    } else if (i == ')') {
      solve();
      op.pop_back();
    } else {
      int v = i - '0';
      vector<pair<int, int> > temp(101, make_pair(-inf, inf));
      temp[0] = make_pair(v, v);
      ans.push_back(temp);
    }
  }
  cout << ans[0][min(p, m)].first;
  return 0;
}
