#include <bits/stdc++.h>
using namespace std;
int Add(int &a, int b) { a = (a + b) % 1000000007; }
int Min(int &a, int b) { a = (a + 1000000007 - b) % 1000000007; }
int Mul(int &a, int b) { a = (long long)a * b % 1000000007; }
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long pow(long long a, long long b) {
  long long res(1);
  while (b) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    b >>= 1;
  }
  return res;
}
long long powM(long long a, long long b, long long mod) {
  long long res(1);
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
const int infi = 2147483647;
const long long infl = 9223372036854775807;
int n, p, m, flag, k;
int pre[10001];
char s[10001];
struct node {
  int type;
  node *ls, *rs;
  int sz;
  node() { type = 0, ls = rs = NULL; }
} pool[10001];
int tot;
node *newnode() { return pool + (tot++); }
int num(char c) {
  if (c == '+') return 10;
  if (c == '-') return 11;
  if (c >= '1' && c <= '9') return c - '0';
  return 0;
}
int pr[10001];
node *build(int l, int r) {
  node *tmp = newnode();
  tmp->sz = 1;
  if (s[l + 1] != '(') {
    if (s[r - 1] != ')') {
      tmp->ls = newnode();
      tmp->ls->type = num(s[l + 1]);
      tmp->rs = newnode();
      tmp->rs->type = num(s[r - 1]);
    } else {
      tmp->ls = newnode();
      tmp->ls->type = num(s[l + 1]);
      tmp->rs = build(l + 3, r - 1);
    }
  } else if (s[r - 1] != ')') {
    tmp->rs = newnode();
    tmp->rs->type = num(s[r - 1]);
    tmp->ls = build(l + 1, r - 3);
  } else {
    int mid = pr[r - 1] - 1;
    tmp->ls = build(l + 1, mid - 1);
    tmp->rs = build(mid + 1, r - 1);
  }
  tmp->sz += tmp->ls->sz;
  tmp->sz += tmp->rs->sz;
  return tmp;
}
long long dp1[10001][101], dp2[10001][101];
int idx(node *x) { return x - pool; }
void solve(node *now, int i) {
  if (now->type) {
    dp1[i][0] = dp2[i][0] = now->type;
    return;
  }
  int l = idx(now->ls), r = idx(now->rs), sz = now->sz;
  solve(now->ls, l), solve(now->rs, r);
  if (now->ls->type && now->rs->type) {
    if (p < m) {
      dp1[i][1] = dp1[l][0] + dp1[r][0];
      dp1[i][0] = dp1[l][0] - dp2[r][0];
      dp2[i][0] = dp1[l][0] - dp2[r][0];
      dp2[i][1] = dp1[l][0] + dp1[r][0];
    } else {
      dp1[i][0] = dp1[l][0] + dp1[r][0];
      dp1[i][1] = dp1[l][0] - dp2[r][0];
      dp2[i][1] = dp1[l][0] - dp2[r][0];
      dp2[i][0] = dp1[l][0] + dp1[r][0];
    }
  } else if (!now->ls->type && now->rs->type) {
    if (p < m) {
      dp1[i][0] = min(dp1[i][0], dp1[l][0] - dp2[r][0]);
      dp2[i][0] = max(dp2[i][0], dp2[l][0] - dp1[r][0]);
      for (int x = 1; x <= (min(sz, k)); ++x) {
        dp1[i][x] = min(dp1[i][x], dp1[l][x - 1] + dp1[r][0]);
        dp1[i][x] = min(dp1[i][x], dp1[l][x] - dp2[r][0]);
        dp2[i][x] = max(dp2[i][x], dp2[l][x - 1] + dp2[r][0]);
        dp2[i][x] = max(dp2[i][x], dp2[l][x] - dp1[r][0]);
      }
    } else {
      dp1[i][0] = min(dp1[i][0], dp1[l][0] + dp1[r][0]);
      dp2[i][0] = max(dp2[i][0], dp2[l][0] + dp2[r][0]);
      for (int x = 1; x <= (min(sz, k)); ++x) {
        dp1[i][x] = min(dp1[i][x], dp1[l][x] + dp1[r][0]);
        dp1[i][x] = min(dp1[i][x], dp1[l][x - 1] - dp2[r][0]);
        dp2[i][x] = max(dp2[i][x], dp2[l][x] + dp2[r][0]);
        dp2[i][x] = max(dp2[i][x], dp2[l][x - 1] - dp1[r][0]);
      }
    }
  } else if (now->ls->type && !now->rs->type) {
    if (p < m) {
      dp1[i][0] = min(dp1[i][0], dp1[l][0] - dp2[r][0]);
      dp2[i][0] = max(dp2[i][0], dp2[l][0] - dp1[r][0]);
      for (int x = 1; x <= (min(sz, k)); ++x) {
        dp1[i][x] = min(dp1[i][x], dp1[l][0] + dp1[r][x - 1]);
        dp1[i][x] = min(dp1[i][x], dp1[l][0] - dp2[r][x]);
        dp2[i][x] = max(dp2[i][x], dp2[l][0] + dp2[r][x - 1]);
        dp2[i][x] = max(dp2[i][x], dp2[l][0] - dp1[r][x]);
      }
    } else {
      dp1[i][0] = min(dp1[i][0], dp1[l][0] + dp1[r][0]);
      dp2[i][0] = max(dp2[i][0], dp2[l][0] + dp2[r][0]);
      for (int x = 1; x <= (min(sz, k)); ++x) {
        dp1[i][x] = min(dp1[i][x], dp1[l][0] + dp1[r][x]);
        dp1[i][x] = min(dp1[i][x], dp1[l][0] - dp2[r][x - 1]);
        dp2[i][x] = max(dp2[i][x], dp2[l][0] + dp2[r][x]);
        dp2[i][x] = max(dp2[i][x], dp2[l][0] - dp1[r][x - 1]);
      }
    }
  } else {
    if (p < m) {
      dp1[i][0] = min(dp1[i][0], dp1[l][0] - dp2[r][0]);
      dp2[i][0] = max(dp2[i][0], dp2[l][0] - dp1[r][0]);
      for (int x = 1; x <= (min(sz, k)); ++x) {
        for (int a = 0; a < (x); ++a) {
          dp1[i][x] = min(dp1[i][x], dp1[l][a] + dp1[r][x - a - 1]);
          dp1[i][x] = min(dp1[i][x], dp1[l][a] - dp2[r][x - a]);
          dp2[i][x] = max(dp2[i][x], dp2[l][a] + dp2[r][x - a - 1]);
          dp2[i][x] = max(dp2[i][x], dp2[l][a] - dp1[r][x - a]);
        }
        dp1[i][x] = min(dp1[i][x], dp1[l][x] - dp2[r][0]);
        dp2[i][x] = max(dp2[i][x], dp2[l][x] - dp1[r][0]);
      }
    } else {
      dp1[i][0] = min(dp1[i][0], dp1[l][0] + dp1[r][0]);
      dp2[i][0] = max(dp2[i][0], dp2[l][0] + dp2[r][0]);
      for (int x = 1; x <= (min(sz, k)); ++x) {
        for (int a = 0; a < (x); ++a) {
          dp1[i][x] = min(dp1[i][x], dp1[l][a] + dp1[r][x - a]);
          dp1[i][x] = min(dp1[i][x], dp1[l][a] - dp2[r][x - a - 1]);
          dp2[i][x] = max(dp2[i][x], dp2[l][a] + dp2[r][x - a]);
          dp2[i][x] = max(dp2[i][x], dp2[l][a] - dp1[r][x - a - 1]);
        }
        dp1[i][x] = min(dp1[i][x], dp1[l][x] + dp1[r][0]);
        dp2[i][x] = max(dp2[i][x], dp2[l][x] + dp2[r][0]);
      }
    }
  }
}
stack<int> Q;
int main() {
  scanf("%s %d %d", s + 1, &p, &m);
  n = strlen(s + 1);
  if (n == 1) {
    printf("%d", (s[1] - '0'));
    return 0;
  }
  for (int i = 0; i < (10001); ++i)
    for (int j = 0; j < (101); ++j) dp1[i][j] = 1e9, dp2[i][j] = -1e9;
  for (int i = 1; i <= (n); ++i) {
    if (s[i] == '(') Q.push(i);
    if (s[i] == ')') {
      pr[i] = Q.top();
      Q.pop();
    }
  }
  node *rt = build(1, n);
  flag = p < m;
  k = min(p, m);
  solve(rt, 0);
  long long ans = dp2[0][k];
  printf("%I64d", (ans)), putchar('\n');
  return 0;
}
