#include <bits/stdc++.h>
using namespace std;
const long long p = 1000000007;
struct node {
  node* r;
  node* l;
  bool type = 0;
  int ord = 0;
  int num = 0;
  node() {
    r = nullptr;
    l = nullptr;
  }
};
int ord = 0;
int dp[10001][102][2];
bool visited[10001][102][2];
int siz[10001];
pair<node*, int> parse(string s, int it) {
  if (s[it] == '(') {
    pair<node*, int> a = parse(s, it + 1);
    pair<node*, int> b = parse(s, a.second + 1);
    node* c = new node();
    c->l = a.first;
    c->r = b.first;
    c->ord = ord++;
    c->type = 1;
    return make_pair(c, b.second + 1);
  } else {
    node* c = new node();
    c->num = s[it] - '0';
    c->ord = ord++;
    return make_pair(c, it + 1);
  }
}
void dfs(node* x) {
  if (x->r != NULL) {
    dfs(x->l);
    dfs(x->r);
    siz[x->ord] = siz[x->r->ord] + siz[x->l->ord] + 1;
  } else {
    siz[x->ord] = 0;
  }
}
void dfsdel(node* x) {
  if (x->r != NULL) {
    dfs(x->l);
    dfs(x->r);
    siz[x->ord] = siz[x->r->ord] + siz[x->l->ord] + 1;
  } else {
    siz[x->ord] = 0;
  }
  delete x;
}
bool solve(node* x, int am, bool maxi) {
  if (am > siz[x->ord]) return 0;
  if (visited[x->ord][am][maxi]) return 1;
  visited[x->ord][am][maxi] = 1;
  if (x->r == NULL) {
    dp[x->ord][am][maxi] = x->num;
    return 1;
  } else {
    int m;
    if (maxi)
      m = -10000000;
    else
      m = 10000000;
    for (int i = 0; i < min(am, siz[x->l->ord] + 1); i++) {
      if (!solve(x->l, i, maxi)) continue;
      if (!solve(x->r, am - i - 1, maxi)) continue;
      if (maxi)
        m = max(dp[x->l->ord][i][maxi] + dp[x->r->ord][am - i - 1][maxi], m);
      else
        m = min(dp[x->l->ord][i][maxi] + dp[x->r->ord][am - i - 1][maxi], m);
    }
    if (siz[x->ord] - am > 0) {
      for (int i = 0; i <= min(am, siz[x->l->ord]); i++) {
        if (!solve(x->l, i, maxi)) continue;
        if (!solve(x->r, am - i, !maxi)) continue;
        if (maxi)
          m = max(dp[x->l->ord][i][maxi] - dp[x->r->ord][am - i][!maxi], m);
        else
          m = min(dp[x->l->ord][i][maxi] - dp[x->r->ord][am - i][!maxi], m);
      }
    }
    dp[x->ord][am][maxi] = m;
  }
  return 1;
}
bool solve2(node* x, int am, bool maxi) {
  if (am > siz[x->ord]) return 0;
  if (visited[x->ord][am][maxi]) return 1;
  visited[x->ord][am][maxi] = 1;
  if (x->r == NULL) {
    dp[x->ord][am][maxi] = x->num;
    return 1;
  } else {
    int m;
    if (maxi)
      m = -10000000;
    else
      m = 10000000;
    if (siz[x->ord] - am > 0) {
      for (int i = 0; i <= min(am, siz[x->l->ord]); i++) {
        if (!solve2(x->l, i, maxi)) continue;
        if (!solve2(x->r, am - i, maxi)) continue;
        if (maxi)
          m = max(dp[x->l->ord][i][maxi] + dp[x->r->ord][am - i][maxi], m);
        else
          m = min(dp[x->l->ord][i][maxi] + dp[x->r->ord][am - i][maxi], m);
      }
    }
    for (int i = 0; i < min(am, siz[x->l->ord] + 1); i++) {
      if (!solve2(x->l, i, maxi)) continue;
      if (!solve2(x->r, am - i - 1, !maxi)) continue;
      if (maxi)
        m = max(dp[x->l->ord][i][maxi] - dp[x->r->ord][am - i - 1][!maxi], m);
      else
        m = min(dp[x->l->ord][i][maxi] - dp[x->r->ord][am - i - 1][!maxi], m);
    }
    dp[x->ord][am][maxi] = m;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int p, m;
  cin >> p >> m;
  node* root = parse(s, 0).first;
  dfs(root);
  if (p <= m) {
    solve(root, p, 1);
    cout << dp[root->ord][p][1] << endl;
  } else {
    solve2(root, m, 1);
    cout << dp[root->ord][m][1] << endl;
  }
  dfsdel(root);
}
