#include <bits/stdc++.h>
using namespace std;
int S[10005], jump[10005], Max[10005][105], Min[10005][105];
int Plus, Minus, m, small, big, tot;
char a[10005];
int DFS(int l, int r) {
  int x = ++tot;
  if (l == r) {
    Max[x][0] = Min[x][0] = a[l] - '0';
    return x;
  }
  int _ = a[l + 1] == '(' ? jump[l + 1] + 1 : l + 2;
  int ls = DFS(l + 1, _ - 1);
  int rs = DFS(_ + 1, r - 1);
  for (int j = small; j <= m; j++)
    for (int k = 0; k + small <= j; k++)
      Max[x][j] = max(Max[x][j], Max[ls][k] + Max[rs][j - small - k]),
      Min[x][j] = min(Min[x][j], Min[ls][k] + Min[rs][j - small - k]);
  for (int j = big; j <= m; j++)
    for (int k = 0; k + big <= j; k++)
      Max[x][j] = max(Max[x][j], Max[ls][k] - Min[rs][j - big - k]),
      Min[x][j] = min(Min[x][j], Min[ls][k] - Max[rs][j - big - k]);
  return x;
}
int main() {
  scanf("%s", a + 1);
  scanf("%d%d", &Plus, &Minus);
  small = Plus < Minus;
  big = small ^ 1;
  m = min(Plus, Minus);
  for (int i = strlen(a + 1); i; i--)
    if (a[i] == ')')
      S[++*S] = i;
    else if (a[i] == '(')
      jump[i] = S[(*S)--];
  for (int i = 1; i < 10005; i++)
    for (int j = 0; j <= m; j++) Max[i][j] = -1e9, Min[i][j] = 1e9;
  int rt = DFS(1, strlen(a + 1));
  printf("%d\n", Max[rt][m]);
}
