#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10, mod = 1e9 + 7;
int n, m, k, t, tot;
vector<int> e[maxn];
char a[maxn];
vector<int> dfsum(int x, int n) {
  vector<int> ret(2 * n + 2);
  for (int i = 0; i <= 2 * n + 1; i++) {
    if (i <= n)
      ret[i] = -1e9;
    else
      ret[i] = 1e9;
  }
  if (x <= 0) {
    ret[0] = ret[n + 1] = -x;
  } else {
    vector<int> p = dfsum(e[x][0], n);
    vector<int> q = dfsum(e[x][1], n);
    for (int i = 0; i <= 2 * n + 1; i++) {
      for (int j = 0; j <= 2 * n + 1; j++) {
        if (abs(p[i]) == 1e9 || abs(q[j]) == 1e9) continue;
        int pi = i > n ? i - n - 1 : i, pj = j > n ? j - n - 1 : j;
        if (pi + pj + 1 <= n) {
          ret[pi + pj + 1] = max(ret[pi + pj + 1], p[i] + q[j]);
          ret[pi + pj + 1 + n + 1] = min(ret[pi + pj + 1 + n + 1], p[i] + q[j]);
        }
        if (pi + pj <= n) {
          ret[pi + pj] = max(ret[pi + pj], p[i] - q[j]);
          ret[pi + pj + n + 1] = min(ret[pi + pj + n + 1], p[i] - q[j]);
        }
      }
    }
  }
  return ret;
}
vector<int> dfsub(int x, int n) {
  vector<int> ret(2 * n + 2);
  for (int i = 0; i <= 2 * n + 1; i++) {
    if (i <= n)
      ret[i] = -1e9;
    else
      ret[i] = 1e9;
  }
  if (x <= 0) {
    ret[0] = ret[n + 1] = -x;
  } else {
    vector<int> p = dfsub(e[x][0], n);
    vector<int> q = dfsub(e[x][1], n);
    for (int i = 0; i <= 2 * n + 1; i++) {
      for (int j = 0; j <= 2 * n + 1; j++) {
        if (abs(p[i]) == 1e9 || abs(q[j]) == 1e9) continue;
        int pi = i > n ? i - n - 1 : i, pj = j > n ? j - n - 1 : j;
        if (pi + pj + 1 <= n) {
          ret[pi + pj + 1] = max(ret[pi + pj + 1], p[i] - q[j]);
          ret[pi + pj + 1 + n + 1] = min(ret[pi + pj + 1 + n + 1], p[i] - q[j]);
        }
        if (pi + pj <= n) {
          ret[pi + pj] = max(ret[pi + pj], p[i] + q[j]);
          ret[pi + pj + n + 1] = min(ret[pi + pj + n + 1], p[i] + q[j]);
        }
      }
    }
  }
  return ret;
}
int main() {
  int i, j;
  vector<int> pos;
  scanf("%s%d%d", a, &n, &m);
  if (!n && !m) {
    printf("%d\n", a[0] - '0');
    return 0;
  }
  for (i = 0; a[i]; i++) {
    if (a[i] == '(')
      pos.push_back(++tot);
    else if (a[i] == ')') {
      int x = pos.back();
      pos.pop_back();
      if (pos.size()) e[pos.back()].push_back(x);
    } else if (a[i] == '?')
      continue;
    else
      e[pos.back()].push_back(-(a[i] - '0'));
  }
  if (n <= m)
    printf("%d\n", dfsum(1, n)[n]);
  else
    printf("%d\n", dfsub(1, m)[m]);
  return 0;
}
