#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1);
using namespace std;
const int MAX = 10 << 10;
char buffer[MAX];
int val[MAX], node_cnt;
int close[MAX];
int L[MAX], R[MAX], siz[MAX];
void preparse() {
  vector<int> ST;
  int N = strlen(buffer);
  for (int i = 0; i < N; i++) {
    if (buffer[i] == '(')
      ST.push_back(i);
    else if (buffer[i] == ')') {
      close[ST.back()] = i;
      ST.pop_back();
    }
  }
}
int parse(int s, int e) {
  assert(s <= e);
  if (s == e) {
    assert(isdigit(buffer[s]));
    int u = node_cnt++;
    val[u] = buffer[s] - '0';
    return u;
  }
  if (isdigit(buffer[s])) {
    assert(buffer[s + 1] == '?');
    int u = node_cnt++;
    val[u] = -1;
    L[u] = parse(s, s);
    R[u] = parse(s + 2, e);
    siz[u] = siz[L[u]] + siz[R[u]] + 1;
    return u;
  }
  if (close[s] == e) return parse(s + 1, e - 1);
  int u = node_cnt++;
  val[u] = -1;
  L[u] = parse(s, close[s]);
  R[u] = parse(close[s] + 2, e);
  siz[u] = siz[L[u]] + siz[R[u]] + 1;
  return u;
}
vector<int> dp[MAX][2];
vector<int> vis[MAX][2];
int solve(int u, int plus, int obj) {
  assert(plus <= siz[u]);
  if (val[u] != -1) return val[u];
  int& ret = dp[u][obj][plus];
  if (vis[u][obj][plus]) return ret;
  vis[u][obj][plus] = 1;
  if (obj == 1)
    ret = -(1 << 29);
  else
    ret = (1 << 29);
  for (int c = 0; c <= 1; c++) {
    for (int lp = max(0, plus - c - siz[R[u]]);
         lp + c <= plus && lp <= siz[L[u]]; lp++) {
      int a = solve(L[u], lp, obj);
      int nobj = 0;
      if (obj == 1)
        nobj = c;
      else
        nobj = c ^ 1;
      int b = solve(R[u], plus - lp - c, nobj);
      int val = a + b;
      if (c == 0) val = a - b;
      if (obj == 1)
        ret = max(ret, val);
      else
        ret = min(ret, val);
    }
  }
  return ret;
}
int main() {
  int plus, minus;
  cin >> buffer >> plus >> minus;
  preparse();
  int root = parse(0, strlen(buffer) - 1);
  assert(siz[root] == plus + minus);
  for (int i = 0; i < (node_cnt); i++) {
    for (int j = 0; j < (2); j++) {
      dp[i][j].resize(siz[i] + 1, 0);
      vis[i][j].resize(siz[i] + 1, 0);
    }
  }
  cout << solve(root, plus, 1) << endl;
  return 0;
}
