#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
void setmax(int &a, int b) {
  if (a < b) {
    a = b;
  }
}
void setmin(int &a, int b) {
  if (a > b) {
    a = b;
  }
}
char S[MAXN];
int P, M, PM;
int V;
int par[MAXN], ch[MAXN][2];
int dpmn[MAXN][110], dpmx[MAXN][110];
bool B;
void dfs(int x) {
  if (x == 0) {
    return;
  }
  int cl = ch[x][0], cr = ch[x][1];
  dfs(cl);
  dfs(cr);
  for (int i = 0; i <= PM; i++) {
    for (int j = 0; j + i <= PM; j++) {
      setmax(dpmx[x][i + j + !B], dpmx[cl][i] + dpmx[cr][j]);
      setmax(dpmx[x][i + j + B], dpmx[cl][i] - dpmn[cr][j]);
      setmin(dpmn[x][i + j + !B], dpmn[cl][i] + dpmn[cr][j]);
      setmin(dpmn[x][i + j + B], dpmn[cl][i] - dpmx[cr][j]);
    }
  }
}
int main() {
  memset((dpmx), (-63), sizeof(dpmx));
  memset((dpmn), (63), sizeof(dpmn));
  scanf("%s %d %d", S + 1, &P, &M);
  PM = min(P, M);
  B = (P > M);
  int cur = ++V;
  for (int i = 1; S[i]; i++) {
    if (S[i] == '?' || S[i] == '(') {
      ch[cur][bool(ch[cur][0])] = ++V;
      par[V] = cur;
      cur = V;
    } else if (S[i] == ')') {
      cur = par[cur];
    } else {
      dpmn[cur][0] = dpmx[cur][0] = S[i] - '0';
      cur = par[cur];
    }
  }
  dfs(1);
  printf("%d\n", dpmx[1][PM]);
}
