#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4, maxk = 100;
const int inf = 1e9;
inline void Min(int &a, int b) {
  if (b < a) a = b;
}
inline void Max(int &a, int b) {
  if (b > a) a = b;
}
struct Node {
  int lc, rc;
} node[maxn];
int cnt_node, n;
char s[maxn + 1];
int size[maxn];
int dpmax[maxn][maxk + 2];
int dpmin[maxn][maxk + 2];
int cntplus, cntminus;
char special;
int cur;
int Build(void) {
  if (isdigit(s[cur])) {
    node[cnt_node] = {-1, s[cur++] - '0'};
    return cnt_node++;
  }
  int u = cnt_node++;
  ++cur;
  node[u].lc = Build();
  ++cur;
  node[u].rc = Build();
  ++cur;
  return u;
}
void Calc(int u) {
  if (node[u].lc == -1) {
    size[u] = 0;
    dpmax[u][0] = dpmin[u][0] = node[u].rc;
  } else {
    int a = node[u].lc, b = node[u].rc;
    size[u] = min(size[a] + size[b] + 1, maxk);
    for (int i = 0; i <= size[u]; ++i) {
      dpmax[u][i] = -inf;
      dpmin[u][i] = inf;
    }
    for (int i = 0; i <= size[a]; ++i) {
      for (int j = 0; j <= size[b]; ++j) {
        if (i + j > size[u]) continue;
        Min(dpmin[u][i + j + (special == '+')], dpmin[a][i] + dpmin[b][j]);
        Min(dpmin[u][i + j + (special == '-')], dpmin[a][i] - dpmax[b][j]);
        Max(dpmax[u][i + j + (special == '+')], dpmax[a][i] + dpmax[b][j]);
        Max(dpmax[u][i + j + (special == '-')], dpmax[a][i] - dpmin[b][j]);
      }
    }
  }
}
int main(void) {
  scanf("%s", s);
  n = strlen(s);
  Build();
  scanf("%d%d", &cntplus, &cntminus);
  if (cntplus < cntminus) {
    special = '+';
  } else {
    special = '-';
  }
  for (int i = cnt_node - 1; i >= 0; --i) {
    Calc(i);
  }
  printf("%d\n", dpmax[0][min(cntplus, cntminus)]);
  return 0;
}
