#include <bits/stdc++.h>
using namespace std;
void read(long long &x) { scanf("%lld", &x); }
void read(long long &x, long long &y) { scanf("%lld%lld", &x, &y); }
void read(long long &x, long long &y, long long &z) {
  scanf("%lld%lld%lld", &x, &y, &z);
}
void print(long long x) { printf("%lld ", x); }
void println(long long x) { printf("%lld\n", x); }
const long long N = 10000;
long long n, sz, a[N + 10], g, h, d[2][111][N + 10], cnt[N + 10];
char s[N + 10];
vector<long long> v[N + 10];
long long build(long long l, long long r) {
  long long pos = l, bal = 0, root, calc = 0;
  for (long long i = l; i <= r; i++) {
    if (s[i] == '(') bal++;
    if (s[i] == ')') bal--;
    if (s[i] == '?') calc++;
    if (s[i] == '?' && bal == 1) pos = i;
  }
  root = ++sz;
  cnt[root] = calc;
  if (pos > l)
    v[root].push_back(build(l + 1, pos - 1)),
        v[root].push_back(build(pos + 1, r - 1));
  else {
    a[root] = s[l] - 48;
    d[0][0][root] = d[1][0][root] = a[root];
  }
  return root;
}
void dfs(long long x) {
  if (v[x].empty()) return;
  long long le = v[x][0], ri = v[x][1];
  dfs(le);
  dfs(ri);
  long long mn = min(cnt[x], min(g, h));
  for (long long i = 0; i <= mn; i++) {
    d[1][i][x] = -2e9;
    d[0][i][x] = 2e9;
    if (cnt[x] - i > max(g, h)) continue;
    if (g < h) {
      for (long long j = 0; j <= i; j++) {
        if (j <= cnt[le] && i - j - 1 >= 0 && i - j - 1 <= cnt[ri])
          d[1][i][x] = max(d[1][i][x], d[1][j][le] + d[1][i - j - 1][ri]);
        if (j <= cnt[le] && i - j - 1 >= 0 && i - j - 1 <= cnt[ri])
          d[0][i][x] = min(d[0][i][x], d[0][j][le] + d[0][i - j - 1][ri]);
      }
      for (long long j = 0; j <= i; j++) {
        if (j <= cnt[le] && i - j <= cnt[ri])
          d[1][i][x] = max(d[1][i][x], d[1][j][le] - d[0][i - j][ri]);
        if (j <= cnt[le] && i - j <= cnt[ri])
          d[0][i][x] = min(d[0][i][x], d[0][j][le] - d[1][i - j][ri]);
      }
    } else {
      for (long long j = 0; j <= i; j++) {
        if (j <= cnt[le] && i - j <= cnt[ri])
          d[1][i][x] = max(d[1][i][x], d[1][j][le] + d[1][i - j][ri]);
        if (j <= cnt[le] && i - j <= cnt[ri])
          d[0][i][x] = min(d[0][i][x], d[0][j][le] + d[0][i - j][ri]);
      }
      for (long long j = 0; j <= i; j++) {
        if (j <= cnt[le] && i - j - 1 >= 0 && i - j - 1 <= cnt[ri])
          d[1][i][x] = max(d[1][i][x], d[1][j][le] - d[0][i - j - 1][ri]);
        if (j <= cnt[le] && i - j - 1 >= 0 && i - j - 1 <= cnt[ri])
          d[0][i][x] = min(d[0][i][x], d[0][j][le] - d[1][i - j - 1][ri]);
      }
    }
  }
}
int main() {
  scanf("%s", s);
  cin >> g >> h;
  n = strlen(s);
  build(0, n - 1);
  dfs(1);
  cout << d[1][min(g, h)][1];
}
