#include <bits/stdc++.h>
using namespace std;
void FAST() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
long long p, m;
vector<pair<long long, pair<long long, long long> > > traverse(long long node,
                                                               string str) {
  if (str[0] == '(') str.erase(str.begin());
  if (str[str.length() - 1] == ')') str.pop_back();
  if (str.length() == 1) {
    vector<pair<long long, pair<long long, long long> > > temp;
    temp.push_back(make_pair(str[0] - '0', make_pair(0, 0)));
    return temp;
  }
  long long pos = -1;
  long long cnt = 0;
  for (long long i = 0; i < str.length(); i++) {
    if (str[i] == '(') cnt++;
    if (str[i] == ')') cnt--;
    if (str[i] == '?' && cnt == 0) {
      pos = i;
      break;
    }
  }
  vector<pair<long long, pair<long long, long long> > > q1 =
      traverse(2 * node + 1, str.substr(0, pos));
  vector<pair<long long, pair<long long, long long> > > q2 =
      traverse(2 * node + 2, str.substr(pos + 1, str.length() - pos));
  vector<pair<long long, pair<long long, long long> > > q;
  map<pair<long long, long long>, long long> mx, mn;
  for (long long i = 0; i < q1.size(); i++)
    for (long long j = 0; j < q2.size(); j++) {
      long long val1 = q1[i].first;
      long long val2 = q2[j].first;
      long long p1 = q1[i].second.first;
      long long p2 = q2[j].second.first;
      long long m1 = q1[i].second.second;
      long long m2 = q2[j].second.second;
      if (p1 + p2 + 1 <= p && m1 + m2 <= m) {
        if (mx.find(make_pair(p1 + p2 + 1, m1 + m2)) == mx.end())
          mx[make_pair(p1 + p2 + 1, m1 + m2)] = val1 + val2;
        else
          mx[make_pair(p1 + p2 + 1, m1 + m2)] =
              max(mx[make_pair(p1 + p2 + 1, m1 + m2)], val1 + val2);
        if (mn.find(make_pair(p1 + p2 + 1, m1 + m2)) == mn.end())
          mn[make_pair(p1 + p2 + 1, m1 + m2)] = val1 + val2;
        else
          mn[make_pair(p1 + p2 + 1, m1 + m2)] =
              min(mn[make_pair(p1 + p2 + 1, m1 + m2)], val1 + val2);
      }
      if (p1 + p2 <= p && m1 + m2 + 1 <= m) {
        if (mx.find(make_pair(p1 + p2, m1 + m2 + 1)) == mx.end())
          mx[make_pair(p1 + p2, m1 + m2 + 1)] = val1 - val2;
        else
          mx[make_pair(p1 + p2, m1 + m2 + 1)] =
              max(mx[make_pair(p1 + p2, m1 + m2 + 1)], val1 - val2);
        if (mn.find(make_pair(p1 + p2, m1 + m2 + 1)) == mn.end())
          mn[make_pair(p1 + p2, m1 + m2 + 1)] = val1 - val2;
        else
          mn[make_pair(p1 + p2, m1 + m2 + 1)] =
              min(mn[make_pair(p1 + p2, m1 + m2 + 1)], val1 - val2);
      }
    }
  for (map<pair<long long, long long>, long long>::iterator itr = mx.begin();
       itr != mx.end(); itr++)
    q.push_back(make_pair(itr->second, itr->first));
  for (map<pair<long long, long long>, long long>::iterator itr = mn.begin();
       itr != mn.end(); itr++)
    q.push_back(make_pair(itr->second, itr->first));
  return q;
}
int main() {
  FAST();
  string str;
  cin >> str;
  cin >> p >> m;
  vector<pair<long long, pair<long long, long long> > > temp = traverse(0, str);
  long long mx = LONG_LONG_MIN;
  for (long long i = 0; i < temp.size(); i++) mx = max(mx, temp[i].first);
  cout << mx << endl;
  return 0;
}
struct Query {
  long long L, R, idx;
};
bool compare(long long a0, long long a1) { return (a0 > a1); }
long long power(long long x, long long y, long long p) {
  long long ans = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return ans;
}
long long x, y, g;
void extendedEuclid(long long a, long long b) {
  if (b == 0) {
    g = a;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(b, a % b);
    long long temp = x;
    x = y;
    y = temp - (a / b) * y;
  }
}
long long moduloInverse(long long a, long long p) {
  extendedEuclid(a, p);
  if (g == 1 && p != 1)
    return (x + p) % p;
  else
    return -1;
}
