#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double eps = 1e-10;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
int dcmp(double x) {
  if (fabs(x) < eps) return 0;
  return x < 0 ? -1 : 1;
}
const int MAXN = 1e4 + 10;
char s[MAXN];
int dp[MAXN][105][2], a[MAXN], cnt[MAXN], tmp[105][2];
stack<int> S;
void up0(int &a, int b) { a = min(a, b); }
void up1(int &a, int b) { a = max(a, b); }
void solve(int sta) {
  int n = 0;
  while (!S.empty()) {
    int x = S.top();
    S.pop();
    if (!x) break;
    a[++n] = x;
  }
  for (int ii = n - 1; ii >= 1; ii--) {
    int v = a[ii + 1], u = a[ii];
    for (int i = min(100, cnt[u] + cnt[v] + 1); i >= 0; i--) {
      tmp[i][0] = INF, tmp[i][1] = -INF;
    }
    for (int i = 0; i <= cnt[u]; i++) {
      for (int j = 0; j <= cnt[v]; j++) {
        if (i + j > 100) break;
        if (sta) {
          up0(tmp[i + j + 1][0], dp[v][j][0] + dp[u][i][0]);
          up1(tmp[i + j + 1][1], dp[v][j][1] + dp[u][i][1]);
          up0(tmp[i + j][0], dp[v][j][0] - dp[u][i][1]);
          up1(tmp[i + j][1], dp[v][j][1] - dp[u][i][0]);
        } else {
          up0(tmp[i + j][0], dp[v][j][0] + dp[u][i][0]);
          up1(tmp[i + j][1], dp[v][j][1] + dp[u][i][1]);
          up0(tmp[i + j + 1][0], dp[v][j][0] - dp[u][i][1]);
          up1(tmp[i + j + 1][1], dp[v][j][1] - dp[u][i][0]);
        }
      }
    }
    cnt[u] = min(cnt[v] + cnt[u] + 1, 100);
    for (int i = 0; i <= cnt[u]; i++) {
      dp[u][i][0] = tmp[i][0];
      dp[u][i][1] = tmp[i][1];
    }
  }
  S.push(a[1]);
}
int main() {
  int n1, n2, len;
  scanf("%s%d%d", s + 1, &n1, &n2);
  len = strlen(s + 1);
  for (int i = 1; i <= len; i++) {
    if (s[i] == '(')
      S.push(0);
    else if (s[i] == ')')
      solve(n1 < n2);
    else if (s[i] == '?')
      continue;
    else {
      S.push(i);
      dp[i][0][0] = dp[i][0][1] = s[i] - '0';
    }
  }
  int t = min(n1, n2), x = S.top();
  printf("%d\n", dp[x][t][1]);
  return 0;
}
