#include <bits/stdc++.h>
using namespace std;
long long qp(long long a, long long b, long long mod) {
  long long t = 1;
  while (b) {
    if (b & 1) t = t * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return t;
}
struct DOT {
  long long x;
  long long y;
};
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {1, -1, 0, 0};
const int inf = 0x3f3f3f3f;
const long long Linf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
;
const int maxn = 1e4 + 5;
char s[maxn];
int n;
int plu, mis;
int val[maxn], mx[maxn][150], mn[maxn][150];
vector<int> G[maxn];
int flag;
void dfs(int u) {
  for (int j = 0; j < 150; j++) mx[u][j] = -inf, mn[u][j] = inf;
  if (val[u]) {
    mx[u][0] = mn[u][0] = val[u];
    return;
  }
  int l = G[u][0], r = G[u][1];
  dfs(G[u][0]);
  dfs(G[u][1]);
  for (int i = 0; i <= min(plu, mis); i++) {
    if (mx[l][i] == -inf) continue;
    for (int j = 0; j + i <= min(plu, mis); j++) {
      if (mx[r][j] == -inf) continue;
      if (flag == 0 && i + j + 1 <= plu) {
        mx[u][i + j + 1] = max(mx[u][i + j + 1], mx[l][i] + mx[r][j]);
        mn[u][i + j + 1] = min(mn[u][i + j + 1], mn[l][i] + mn[r][j]);
      }
      if (flag == 1 && i + j + 1 <= mis) {
        mn[u][i + j + 1] = min(mn[u][i + j + 1], mn[l][i] - mx[r][j]);
        mx[u][i + j + 1] = max(mx[u][i + j + 1], mx[l][i] - mn[r][j]);
      }
      if (flag == 1) {
        mx[u][i + j] = max(mx[u][i + j], mx[l][i] + mx[r][j]);
        mn[u][i + j] = min(mn[u][i + j], mn[l][i] + mn[r][j]);
      }
      if (flag == 0) {
        mn[u][i + j] = min(mn[u][i + j], mn[l][i] - mx[r][j]);
        mx[u][i + j] = max(mx[u][i + j], mx[l][i] - mn[r][j]);
      }
    }
  }
}
int main() {
  scanf("%s", s + 1);
  scanf("%d%d", &plu, &mis);
  stack<int> stk;
  for (int i = 1; s[i]; i++) {
    if (s[i] == '(')
      stk.push(++n);
    else if (s[i] == ')') {
      int t = stk.top();
      stk.pop();
      if (!stk.empty()) G[stk.top()].push_back(t);
    } else if (s[i] >= '1' && s[i] <= '9') {
      if (stk.empty()) return 0 * printf("%d\n", s[i] - '0');
      G[stk.top()].push_back(++n);
      val[n] = s[i] - '0';
    }
  }
  flag = plu > mis;
  dfs(1);
  printf("%d\n", mx[1][min(plu, mis)]);
}
