#include <bits/stdc++.h>
const int INF = 1000000007;
inline int max(const int &a, const int &b) { return a > b ? a : b; }
inline int min(const int &a, const int &b) { return a < b ? a : b; }
int t[5015][2], f[5005][102], g[5005][102], sz[5005];
int stk[5005], tp, cur, tot = 10, rt;
char str[10010];
bool now;
void dfssz(int x) {
  sz[x] = 1;
  if (t[x][0] > 10) dfssz(t[x][0]), sz[x] += sz[t[x][0]];
  if (t[x][1] > 10) dfssz(t[x][1]), sz[x] += sz[t[x][1]];
}
void init() {
  memset(f, 192, sizeof(f));
  memset(g, 127, sizeof(g));
  int l = strlen(str), fa;
  for (int i = 0; i < l; ++i) {
    if (isdigit(str[i])) cur = str[i] - '0';
    if (str[i] == '?') {
      stk[++tp] = ++tot;
      t[tot][0] = cur;
    }
    if (str[i] == ')') {
      fa = stk[tp--];
      t[fa][1] = cur;
      cur = rt = fa;
    }
  }
  dfssz(rt);
}
int calcMax(int x, int p);
int calcMin(int x, int p) {
  if (p < 0 || p > sz[x]) return INF;
  if (x < 10) return x;
  if (sz[x] == 1) return now == (bool)p ? t[x][0] + t[x][1] : t[x][0] - t[x][1];
  if (g[x][p] < INF) return g[x][p];
  int mn = min(sz[t[x][0]], p), ans1, ans2;
  for (int i = 0; i <= mn; ++i) {
    ans1 = calcMin(t[x][0], i) + calcMin(t[x][1], p - now - i);
    ans2 = calcMin(t[x][0], i) - calcMax(t[x][1], p + now - 1 - i);
    g[x][p] = min(g[x][p], min(ans1, ans2));
  }
  return g[x][p];
}
int calcMax(int x, int p) {
  if (p < 0 || p > sz[x]) return -INF;
  if (x < 10) return x;
  if (sz[x] == 1) return now == (bool)p ? t[x][0] + t[x][1] : t[x][0] - t[x][1];
  if (f[x][p] > -INF) return f[x][p];
  int mn = min(sz[t[x][0]], p), ans1, ans2;
  for (int i = 0; i <= mn; ++i) {
    ans1 = calcMax(t[x][0], i) + calcMax(t[x][1], p - now - i);
    ans2 = calcMax(t[x][0], i) - calcMin(t[x][1], p + now - 1 - i);
    f[x][p] = max(f[x][p], max(ans1, ans2));
  }
  return f[x][p];
}
int main() {
  scanf("%s", str);
  if (strlen(str) == 1) {
    puts(str);
    return 0;
  }
  init();
  int a, b;
  scanf("%d%d", &a, &b);
  if (a < b)
    now = 1;
  else
    now = 0;
  printf("%d", calcMax(rt, now ? a : b));
}
