#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
char str[10002];
int P, M;
int st[10002], top = 0;
int rnum[10002], ncnt = 0;
vector<int> G[10002];
bool is_leaf[10002];
int num[10002];
int dpmx[10002][102], dpmi[10002][102];
bool P_is_min;
void solve(int cur) {
  if (is_leaf[cur]) {
    dpmx[cur][0] = num[cur];
    dpmi[cur][0] = num[cur];
    return;
  }
  int c0 = G[cur][0], c1 = G[cur][1];
  solve(c0);
  solve(c1);
  for (int i = 0; i <= min(P, M); i++) {
    if (P_is_min) {
      for (int j = 0; i - j - 1 >= 0; j++) {
        dpmx[cur][i] = max(dpmx[cur][i], dpmx[c0][j] + dpmx[c1][i - j - 1]);
        dpmi[cur][i] = min(dpmi[cur][i], dpmi[c0][j] + dpmi[c1][i - j - 1]);
      }
      for (int j = 0; i - j >= 0; j++) {
        dpmx[cur][i] = max(dpmx[cur][i], dpmx[c0][j] - dpmi[c1][i - j]);
        dpmi[cur][i] = min(dpmi[cur][i], dpmi[c0][j] - dpmx[c1][i - j]);
      }
    } else {
      for (int j = 0; i - j >= 0; j++) {
        dpmx[cur][i] = max(dpmx[cur][i], dpmx[c0][j] + dpmx[c1][i - j]);
        dpmi[cur][i] = min(dpmi[cur][i], dpmi[c0][j] + dpmi[c1][i - j]);
      }
      for (int j = 0; i - j - 1 >= 0; j++) {
        dpmx[cur][i] = max(dpmx[cur][i], dpmx[c0][j] - dpmi[c1][i - j - 1]);
        dpmi[cur][i] = min(dpmi[cur][i], dpmi[c0][j] - dpmx[c1][i - j - 1]);
      }
    }
  }
}
int main() {
  scanf("%s", str);
  scanf("%d %d", &P, &M);
  int sl = strlen(str);
  if (sl == 1) {
    printf("%c", str[0]);
    return 0;
  }
  for (int i = 0; i < sl; i++) {
    if (str[i] == '(') {
      rnum[i] = ncnt;
      st[top] = ncnt;
      ncnt++;
      top++;
    } else if (str[i] == ')') {
      rnum[i] = st[--top];
    } else if (str[i] == '?') {
      rnum[i] = st[top - 1];
    }
  }
  for (int i = 1; i < sl; i++) {
    if (str[i] != '?') continue;
    if ('0' <= str[i - 1] && str[i - 1] <= '9') {
      num[ncnt] = str[i - 1] - '0';
      is_leaf[ncnt] = true;
      G[rnum[i]].push_back(ncnt);
      ncnt++;
    } else {
      G[rnum[i]].push_back(rnum[i - 1]);
    }
    if ('0' <= str[i + 1] && str[i + 1] <= '9') {
      num[ncnt] = str[i + 1] - '0';
      is_leaf[ncnt] = true;
      G[rnum[i]].push_back(ncnt);
      ncnt++;
    } else {
      G[rnum[i]].push_back(rnum[i + 1]);
    }
  }
  if (min(P, M) == P) P_is_min = true;
  for (int i = 0; i < ncnt; i++)
    for (int j = 0; j <= min(P, M); j++) {
      dpmx[i][j] = -INF;
      dpmi[i][j] = INF;
    }
  solve(0);
  printf("%d", dpmx[0][min(P, M)]);
  return 0;
}
