#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9, N = 10010;
const double eps = 1e-8;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
int n, p, s;
char ch[N];
bool flag = 0;
int mi = 0;
stack<int> sta;
int ne[N];
int f[N][110][2];
int tmp[110][2];
int dfs(int u) {
  int nex = 0, OP = 0, op = 0;
  for (int i = u + 1; i < ne[u]; i = nex + 1) {
    if (ch[i] == '(') {
      op = dfs(i);
      nex = ne[i] + 1;
    } else {
      nex = i + 1;
      f[i][0][0] = f[i][0][1] = ch[i] - '0';
      op = 0;
    }
    if (i == u + 1) {
      OP += op;
      for (int j = 0; j <= mi; j++) {
        f[u][j][1] = f[i][j][1];
        f[u][j][0] = f[i][j][0];
      }
    } else {
      OP += op + 1;
      for (int j = 0; j <= min(mi, OP); j++) {
        tmp[j][1] = f[u][j][1];
        f[u][j][1] = -INF;
        tmp[j][0] = f[u][j][0];
        f[u][j][0] = INF;
      }
      for (int j = 0; j <= min(mi, OP); j++)
        for (int k = 0; k <= j; k++)
          if (!flag) {
            if (j - k <= op) {
              f[u][j][1] = max(f[u][j][1], tmp[k][1] + f[i][j - k][1]);
              f[u][j][0] = min(f[u][j][0], tmp[k][0] + f[i][j - k][0]);
            }
            if (j - k - 1 >= 0 && j - k - 1 <= op) {
              f[u][j][0] = min(f[u][j][0], tmp[k][0] - f[i][j - k - 1][1]);
              f[u][j][1] = max(f[u][j][1], tmp[k][1] - f[i][j - k - 1][0]);
            }
          } else {
            if (j - k <= op) {
              f[u][j][0] = min(f[u][j][0], tmp[k][0] - f[i][j - k][1]);
              f[u][j][1] = max(f[u][j][1], tmp[k][1] - f[i][j - k][0]);
            }
            if (j - k - 1 >= 0 && j - k - 1 <= op) {
              f[u][j][1] = max(f[u][j][1], tmp[k][1] + f[i][j - k - 1][1]);
              f[u][j][0] = min(f[u][j][0], tmp[k][0] + f[i][j - k - 1][0]);
            }
          }
    }
  }
  return OP;
}
int main() {
  scanf("%s", ch + 1);
  n = strlen(ch + 1);
  read(p);
  read(s);
  if (n == 1) {
    printf("%d\n", ch[1] - '0');
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (ch[i] == '(') {
      sta.push(i);
    } else if (ch[i] == ')') {
      ne[sta.top()] = i;
      sta.pop();
    }
  }
  flag = (p <= s);
  mi = min(p, s);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= mi; j++) {
      f[i][j][0] = INF;
      f[i][j][1] = -INF;
    }
  dfs(1);
  printf("%d\n", f[1][mi][1]);
  return 0;
}
