#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long MOD = 1000000007;
long double EPS = 1e-9;
long long binpow(long long b, long long p, long long mod) {
  long long ans = 1;
  b %= mod;
  for (; p; p >>= 1) {
    if (p & 1) ans = ans * b % mod;
    b = b * b % mod;
  }
  return ans;
}
void pre() {}
int p, m;
string s;
int cur;
int val[1000100][2];
int par[1000100];
int lc[1000100];
int rc[1000100];
int sz[1000100];
int newnode;
void parse() {
  int n = s.length();
  cur = 0;
  newnode = 1;
  for (long long i = 0; i < (s.length()); ++i) {
    if (s[i] == '(') {
      lc[cur] = newnode++;
      par[lc[cur]] = cur;
      cur = lc[cur];
    } else if (s[i] == ')') {
      val[cur][0] = val[lc[cur]][0] + val[rc[cur]][0];
      val[cur][1] = val[lc[cur]][1] - val[rc[cur]][1];
      sz[cur] = sz[lc[cur]] + sz[rc[cur]] + 1;
      cur = par[cur];
    } else if (s[i] == '?') {
      rc[cur] = newnode++;
      par[rc[cur]] = cur;
      cur = rc[cur];
    } else {
      val[cur][0] = val[cur][1] = s[i] - '0';
      sz[cur] = 0;
      cur = par[cur];
    }
  }
}
long long dp[10030][101][2];
bool seen[10030][101][2];
long long mode = 0;
long long calc(int nn, int nump, int numm, int type) {
  if (nump > sz[nn] || nump < 0 || numm < 0 || numm > sz[nn])
    return type == 0 ? -MOD * MOD : MOD * MOD;
  if (seen[nn][mode ? numm : nump][type])
    return dp[nn][mode ? numm : nump][type];
  seen[nn][mode ? numm : nump][type] = 1;
  if (sz[nn] == 0) {
    dp[nn][mode ? numm : nump][0] = dp[nn][mode ? numm : nump][1] = val[nn][0];
    return dp[nn][mode ? numm : nump][type];
  }
  if (sz[nn] == nump) {
    dp[nn][mode ? numm : nump][0] = dp[nn][mode ? numm : nump][1] = val[nn][0];
    return val[nn][0];
  }
  if (sz[nn] == numm) {
    dp[nn][mode ? numm : nump][0] = dp[nn][mode ? numm : nump][1] = val[nn][1];
    return val[nn][1];
  }
  if (type == 0) {
    if (mode == 0) {
      dp[nn][nump][0] = -MOD * MOD;
      for (long long i = 0; i < (nump); ++i) {
        (dp[nn][nump][0] =
             max((dp[nn][nump][0]),
                 (calc(lc[nn], i, sz[lc[nn]] - i, 0) +
                  calc(rc[nn], nump - 1 - i, sz[rc[nn]] - (nump - 1 - i), 0))));
      }
      for (long long i = 0; i <= nump; ++i) {
        (dp[nn][nump][0] =
             max((dp[nn][nump][0]),
                 (calc(lc[nn], i, sz[lc[nn]] - i, 0) -
                  calc(rc[nn], nump - i, sz[rc[nn]] - (nump - i), 1))));
      }
      return dp[nn][nump][0];
    } else {
      dp[nn][numm][0] = -MOD * MOD;
      for (long long i = 0; i < (numm); ++i) {
        (dp[nn][numm][0] =
             max((dp[nn][numm][0]),
                 (calc(lc[nn], sz[lc[nn]] - i, i, 0) -
                  calc(rc[nn], sz[rc[nn]] - (numm - 1 - i), numm - 1 - i, 1))));
      }
      for (long long i = 0; i <= numm; ++i) {
        (dp[nn][numm][0] =
             max((dp[nn][numm][0]),
                 (calc(lc[nn], sz[lc[nn]] - i, i, 0) +
                  calc(rc[nn], sz[rc[nn]] - (numm - i), numm - i, 0))));
      }
      return dp[nn][numm][0];
    }
  } else {
    if (mode == 0) {
      dp[nn][nump][1] = MOD * MOD;
      for (long long i = 0; i < (nump); ++i) {
        (dp[nn][nump][1] =
             min((dp[nn][nump][1]),
                 (calc(lc[nn], i, sz[lc[nn]] - i, 1) +
                  calc(rc[nn], nump - 1 - i, sz[rc[nn]] - (nump - 1 - i), 1))));
      }
      for (long long i = 0; i <= nump; ++i) {
        (dp[nn][nump][1] =
             min((dp[nn][nump][1]),
                 (calc(lc[nn], i, sz[lc[nn]] - i, 1) -
                  calc(rc[nn], nump - i, sz[rc[nn]] - (nump - i), 0))));
      }
      return dp[nn][nump][1];
    } else {
      dp[nn][numm][1] = MOD * MOD;
      for (long long i = 0; i < (numm); ++i) {
        (dp[nn][numm][1] =
             min((dp[nn][numm][1]),
                 (calc(lc[nn], sz[lc[nn]] - i, i, 1) -
                  calc(rc[nn], sz[rc[nn]] - (numm - 1 - i), numm - 1 - i, 0))));
      }
      for (long long i = 0; i <= numm; ++i) {
        (dp[nn][numm][1] =
             min((dp[nn][numm][1]),
                 (calc(lc[nn], sz[lc[nn]] - i, i, 1) +
                  calc(rc[nn], sz[rc[nn]] - (numm - i), numm - i, 1))));
      }
      return dp[nn][numm][1];
    }
  }
}
void solve() {
  for (long long i = 0; i < (10030); ++i)
    for (long long j = 0; j < (101); ++j) seen[i][j][0] = seen[i][j][1] = 0;
  cin >> s;
  cin >> p >> m;
  parse();
  if (p > m) mode = 1;
  cout << calc(0, p, m, 0) << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
