#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
int n, m, p, total;
char second[20002];
int pos[20002];
int k;
int g[20002][2];
int val[20002];
int d[20002][101];
int first[20002][101];
int tot[20002];
int go(int l, int r) {
  int v = k++;
  if (l == r) {
    g[v][0] = g[v][1] = -1;
    val[v] = second[l] - '0';
    return v;
  }
  tot[v] = 1;
  g[v][0] = go(l + 1, pos[l] - 1);
  g[v][1] = go(pos[l] + 1, r - 1);
  tot[v] += tot[g[v][0]];
  tot[v] += tot[g[v][1]];
  return v;
}
int state(int P, int M) {
  if (p < 101) {
    return P;
  } else {
    return M;
  }
}
void solve(int v) {
  for (int i = 0; i < 101; ++i) {
    d[v][i] = -INF;
    first[v][i] = INF;
  }
  if (g[v][0] == -1) {
    d[v][0] = val[v];
    first[v][0] = val[v];
    return;
  }
  solve(g[v][0]);
  solve(g[v][1]);
  for (int p1 = min(tot[g[v][0]], p); p1 >= 0; --p1) {
    int m1 = tot[g[v][0]] - p1;
    if (m1 < 0) continue;
    if (m1 > m) break;
    for (int p2 = min(tot[g[v][1]], p); p2 >= 0; --p2) {
      int m2 = tot[g[v][1]] - p2;
      if (m2 < 0) continue;
      if (m2 > m) break;
      int P = p1 + p2 + 1;
      int M = m1 + m2;
      if (P <= p && M <= m) {
        d[v][state(P, M)] =
            max(d[v][state(P, M)],
                d[g[v][0]][state(p1, m1)] + d[g[v][1]][state(p2, m2)]);
        first[v][state(P, M)] =
            min(first[v][state(P, M)],
                first[g[v][0]][state(p1, m1)] + first[g[v][1]][state(p2, m2)]);
      }
      P = p1 + p2;
      M = m1 + m2 + 1;
      if (P <= p && M <= m) {
        d[v][state(P, M)] =
            max(d[v][state(P, M)],
                d[g[v][0]][state(p1, m1)] - first[g[v][1]][state(p2, m2)]);
        first[v][state(P, M)] =
            min(first[v][state(P, M)],
                first[g[v][0]][state(p1, m1)] - d[g[v][1]][state(p2, m2)]);
      }
    }
  }
}
int main() {
  scanf("%s", second);
  n = strlen(second);
  scanf("%d%d", &p, &m);
  stack<int> st;
  for (int i = 0; i < n; ++i) {
    if (second[i] == '(') {
      st.push(i);
    } else if (second[i] == ')') {
      st.pop();
    } else if (second[i] == '?') {
      int j = st.top();
      pos[j] = i;
    }
  }
  go(0, n - 1);
  solve(0);
  printf("%d\n", d[0][state(p, m)]);
  return 0;
}
