#include <bits/stdc++.h>
using namespace std;
inline long long GCD(long long a, long long b) {
  while (b != 0) {
    int t = a;
    a = b;
    b = t % b;
  }
  return a;
}
inline long long LCM(long long a, long long b) {
  if (a == 0 || b == 0) return GCD(a, b);
  return a * b / GCD(a, b);
}
inline long long CEIL(long long n, long long d) { return n / d + n % d != 0; }
inline long long ROUND(long long n, long long d) {
  return n / d + (long long)((n % d) * 2 >= d);
}
inline long long POW(long long a, long long n) {
  if (n < 0) return 0;
  long long ret = 1;
  while (n) {
    if (n % 2) ret *= a;
    a = a * a;
    n /= 2;
  }
  return ret;
}
const int MAXN = 101, INF = 100000;
struct node {
  node *l, *r, *p;
  int bdp[MAXN], mdp[MAXN];
  node(node *p = 0) : l(0), r(0), p(p) {
    fill(bdp, bdp + MAXN, -INF);
    fill(mdp, mdp + MAXN, INF);
  }
  node *child() {
    if (!l)
      return l = new node(this);
    else
      return r = new node(this);
  }
} * root, *cur;
int p, m, n, op;
string str;
void input() { cin >> str >> p >> m; }
void dfs(node *u) {
  if (!u->l) {
    return;
  }
  node *l = u->l, *r = u->r;
  dfs(l), dfs(r);
  for (int(i) = (0); (i) < (int)(n + 1); ++(i)) {
    for (int(j) = (0); (j) < (int)(i + 1); ++(j)) {
      int k = i - j - (op == 1 ? 1 : 0);
      if (k >= 0) u->bdp[i] = max(u->bdp[i], l->bdp[j] + r->bdp[k]);
      if (k >= 0) u->mdp[i] = min(u->mdp[i], l->mdp[j] + r->mdp[k]);
      k = i - j - (op == -1 ? 1 : 0);
      if (k >= 0) u->bdp[i] = max(u->bdp[i], l->bdp[j] - r->mdp[k]);
      if (k >= 0) u->mdp[i] = min(u->mdp[i], l->mdp[j] - r->bdp[k]);
    }
  }
}
int solve() {
  if (p > m)
    n = m, op = -1;
  else
    n = p, op = 1;
  root = cur = new node();
  for (int(i) = (0); (i) < (int)(str.size()); ++(i)) {
    switch (str[i]) {
      case '(':
      case '?':
        cur = cur->child();
        break;
      case ')':
        cur = cur->p;
        break;
      default:
        cur->bdp[0] = cur->mdp[0] = str[i] - '0';
        cur = cur->p;
    }
  }
  assert(cur == 0);
  dfs(root);
  cout << root->bdp[n] << '\n';
  return 0;
}
void execute() { input(), solve(); }
int main(void) {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  execute();
  return 0;
}
