#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n;
char s[100005];
int a, b, len, rt, pos;
int ch[100005][2];
int getnode() {
  int x = ++n;
  pos++;
  if (s[pos] == '(')
    ch[x][0] = getnode();
  else {
    ch[x][0] = -(s[pos] - '0');
  }
  pos++;
  pos++;
  if (s[pos] == '(')
    ch[x][1] = getnode();
  else {
    ch[x][1] = -(s[pos] - '0');
  }
  pos++;
  return x;
}
int f[3505][3505], vis[3505][3505];
int g[3505][3505], vi2[3505][3505];
int siz[4005];
void dfs(int x) {
  siz[x] = 1;
  if (ch[x][0] > 0) {
    dfs(ch[x][0]);
    siz[x] += siz[ch[x][0]];
  }
  if (ch[x][1] > 0) {
    dfs(ch[x][1]);
    siz[x] += siz[ch[x][1]];
  }
}
int dp2(int x, int d);
int dp(int x, int d) {
  if (vis[x][d]) return f[x][d];
  vis[x][d] = 1;
  if (ch[x][0] < 0 && ch[x][1] < 0) {
    if (d == 0)
      return f[x][d] = (-ch[x][0]) - (-ch[x][1]);
    else
      return f[x][d] = (-ch[x][0]) + (-ch[x][1]);
  }
  if (ch[x][0] > 0 && ch[x][1] < 0) {
    int ret = -0x3f3f3f3f;
    if (d <= siz[ch[x][0]]) ret = max(ret, dp(ch[x][0], d) - (-ch[x][1]));
    if (d) ret = max(ret, dp(ch[x][0], d - 1) + (-ch[x][1]));
    return f[x][d] = ret;
  }
  if (ch[x][0] < 0 && ch[x][1] > 0) {
    int ret = -0x3f3f3f3f;
    if (d <= siz[ch[x][1]]) ret = max(ret, (-ch[x][0]) - dp2(ch[x][1], d));
    if (d) ret = max(ret, (-ch[x][0]) + dp(ch[x][1], d - 1));
    return f[x][d] = ret;
  }
  if (ch[x][0] > 0 && ch[x][1] > 0) {
    int ret = -0x3f3f3f3f;
    if (d == siz[x])
      return f[x][d] =
                 dp(ch[x][0], siz[ch[x][0]]) + dp(ch[x][1], siz[ch[x][1]]);
    int mx = min(d, siz[ch[x][0]]);
    int mn = max(0, d - siz[ch[x][1]]);
    for (int i = mn; i <= mx; i++) {
      ret = max(ret, dp(ch[x][0], i) - dp2(ch[x][1], d - i));
    }
    d--;
    mx = min(d, siz[ch[x][0]]);
    mn = max(0, d - siz[ch[x][1]]);
    for (int i = mn; i <= mx; i++) {
      ret = max(ret, dp(ch[x][0], i) + dp(ch[x][1], d - i));
    }
    return f[x][d + 1] = ret;
  }
}
int dp2(int x, int d) {
  if (vi2[x][d]) return g[x][d];
  vi2[x][d] = 1;
  if (ch[x][0] < 0 && ch[x][1] < 0) {
    if (d == 0)
      return g[x][d] = (-ch[x][0]) - (-ch[x][1]);
    else
      return g[x][d] = (-ch[x][0]) + (-ch[x][1]);
  }
  if (ch[x][0] > 0 && ch[x][1] < 0) {
    int ret = 0x3f3f3f3f;
    if (d <= siz[ch[x][0]]) ret = min(ret, dp2(ch[x][0], d) - (-ch[x][1]));
    if (d) ret = min(ret, dp2(ch[x][0], d - 1) + (-ch[x][1]));
    return g[x][d] = ret;
  }
  if (ch[x][0] < 0 && ch[x][1] > 0) {
    int ret = 0x3f3f3f3f;
    if (d <= siz[ch[x][1]]) ret = min(ret, (-ch[x][0]) - dp(ch[x][1], d));
    if (d) ret = min(ret, (-ch[x][0]) + dp2(ch[x][1], d - 1));
    return g[x][d] = ret;
  }
  if (ch[x][0] > 0 && ch[x][1] > 0) {
    int ret = 0x3f3f3f3f;
    if (d == siz[x])
      return g[x][d] =
                 dp2(ch[x][0], siz[ch[x][0]]) + dp2(ch[x][1], siz[ch[x][1]]);
    int mx = min(d, siz[ch[x][0]]);
    int mn = max(0, d - siz[ch[x][1]]);
    for (int i = mn; i <= mx; i++) {
      ret = min(ret, dp2(ch[x][0], i) - dp(ch[x][1], d - i));
    }
    d--;
    mx = min(d, siz[ch[x][0]]);
    mn = max(0, d - siz[ch[x][1]]);
    for (int i = mn; i <= mx; i++) {
      ret = min(ret, dp2(ch[x][0], i) + dp2(ch[x][1], d - i));
    }
    return g[x][d + 1] = ret;
  }
}
int main() {
  scanf("%s", s + 1);
  scanf("%d%d", &a, &b);
  len = strlen(s + 1);
  if (len == 1) {
    printf("%c\n", s[1]);
    return 0;
  }
  pos = 1;
  rt = getnode();
  memset(f, -0x3f3f3f3f, sizeof(f));
  memset(g, 0x3f3f3f3f, sizeof(g));
  dfs(1);
  int ans = dp(rt, a);
  printf("%d\n", ans);
  return 0;
}
