#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
bool IsPowerOfTwo(long long int x) { return (x != 0) && ((x & (x - 1)) == 0); }
long long int poer(long long int a, long long int b) {
  long long int rs = 1;
  while (b > 0) {
    if (b & 1) rs *= a;
    a *= a;
    b /= 2;
  }
  return rs;
}
long long int mod_poer(long long int a, long long int b, long long int mo) {
  long long int rs = 1;
  while (b > 0) {
    if (b & 1) rs = (rs * a) % mo;
    a = (a * a) % mo;
    b /= 2;
  }
  return rs % mo;
}
long long int d, x, y;
void ext_euclid(long long int a, long long int b) {
  if (b == 0) {
    d = a;
    x = 1;
    y = 0;
  } else {
    ext_euclid(b, a % b);
    long long int temp = x;
    x = y;
    y = temp - (a / b) * y;
  }
}
long long int mod_inverse1(long long int a, long long int m) {
  ext_euclid(a, m);
  return (x % m + m) % m;
}
long long int mod_inverse2(long long int a, long long int m) {
  return mod_poer(a, m - 2, m);
}
long long int gcd(long long int a, long long int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long int fact[200005];
void fac() {
  fact[1] = fact[0] = 1;
  for (long long int i = 2; i <= 200005; ++i) {
    fact[i] = ((fact[i - 1] % MOD) * i) % MOD;
  }
}
long long int combi(long long int a, long long int b) {
  if (b > a) return 0;
  if (b == a)
    return 1;
  else {
    long long int x = mod_poer(fact[b], MOD - 2, MOD) % MOD;
    long long int y = mod_poer(fact[a - b], MOD - 2, MOD) % MOD;
    return ((((fact[a]) * x) % MOD) * y) % MOD;
  }
}
vector<long long int> adj[10001];
long long int ds[10001];
string s;
long long int cur = 0, p, m, isroot[10001];
long long int make_tree(long long int& p) {
  long long int u, w, v, r;
  if (s[p] == '(') {
    p++;
    u = make_tree(p);
  } else {
    u = cur;
    ds[cur] = s[p] - '0';
    cur++;
  }
  p++;
  w = cur;
  r = cur;
  ds[cur] = -1;
  cur++;
  p++;
  if (s[p] == '(') {
    p++;
    v = make_tree(p);
  } else {
    v = cur;
    ds[cur] = s[p] - '0';
    cur++;
  }
  p++;
  adj[w].push_back(u);
  adj[w].push_back(v);
  isroot[u] = 1;
  isroot[v] = 1;
  return r;
}
long long int sub[10001];
long long int compute(long long int u) {
  long long int cnt = 0;
  if (ds[u] == -1) {
    cnt++;
  }
  for (long long int i = 0; i < adj[u].size(); i++) {
    long long int v = adj[u][i];
    cnt += compute(v);
  }
  sub[u] = cnt;
  return cnt;
}
long long int mx[10001][101];
long long int mn[10001][101];
long long int sp = 0;
void solve(long long int w, long long int m) {
  if (mx[w][m] != -1) {
    return;
  }
  if (adj[w].size() == 0) {
    mx[w][m] = ds[w];
    mn[w][m] = ds[w];
    return;
  }
  long long int u = adj[w][0];
  long long int v = adj[w][1];
  long long int p = sub[w] - m;
  long long int mxx = -1e15;
  long long int mnn = 1e15;
  long long int t = m - sp;
  for (long long int i = 0; i <= t; i++) {
    if (i > sub[u] || t - i > sub[v]) {
      continue;
    }
    solve(u, i);
    solve(v, t - i);
    mxx = max(mxx, mx[u][i] + mx[v][t - i]);
    mxx = max(mxx, mx[u][i] + mn[v][t - i]);
    mxx = max(mxx, mn[u][i] + mx[v][t - i]);
    mxx = max(mxx, mn[u][i] + mn[v][t - i]);
    mnn = min(mnn, mx[u][i] + mx[v][t - i]);
    mnn = min(mnn, mx[u][i] + mn[v][t - i]);
    mnn = min(mnn, mn[u][i] + mx[v][t - i]);
    mnn = min(mnn, mn[u][i] + mn[v][t - i]);
  }
  t = m - (sp ^ 1);
  for (long long int i = 0; i <= t; i++) {
    if (i > sub[u] || t - i > sub[v]) {
      continue;
    }
    solve(u, i);
    solve(v, t - i);
    mxx = max(mxx, mx[u][i] - mx[v][t - i]);
    mxx = max(mxx, mx[u][i] - mn[v][t - i]);
    mxx = max(mxx, mn[u][i] - mx[v][t - i]);
    mxx = max(mxx, mn[u][i] - mn[v][t - i]);
    mnn = min(mnn, mx[u][i] - mx[v][t - i]);
    mnn = min(mnn, mx[u][i] - mn[v][t - i]);
    mnn = min(mnn, mn[u][i] - mx[v][t - i]);
    mnn = min(mnn, mn[u][i] - mn[v][t - i]);
  }
  mx[w][m] = mxx;
  mn[w][m] = mnn;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  getline(cin, s);
  cin >> p >> m;
  if (s.size() == 1) {
    cout << s << endl;
    return 0;
  }
  long long int t = 1;
  make_tree(t);
  long long int root;
  for (long long int i = 0; i < 10001; i++) {
    if (!isroot[i]) {
      root = i;
      break;
    }
  }
  compute(root);
  long long int tmp;
  if (m < p) {
    tmp = m;
  } else {
    sp = 1;
    tmp = p;
  }
  for (long long int i = 0; i < 10001; i++) {
    for (long long int j = 0; j < 101; j++) {
      mx[i][j] = -1;
      mn[i][j] = -1;
    }
  }
  solve(root, tmp);
  cout << mx[root][tmp] << endl;
  return 0;
}
