#include <bits/stdc++.h>
using namespace std;
int p = 0, cnt = 0, cplus, cminus, val[10005], Child[10005];
pair<int, int> F[10005][105], FF[105];
string s;
vector<int> g[10005];
void DFS(int u) {
  while (p < s.size()) {
    p++;
    if (s[p - 1] == '(') {
      g[u].push_back(++cnt);
      DFS(cnt);
    } else if ('0' <= s[p - 1] && s[p - 1] <= '9') {
      val[++cnt] = s[p - 1] - '0';
      g[u].push_back(cnt);
    } else if (s[p - 1] == ')')
      break;
  }
}
void FinalDFS(int u, int root) {
  for (int i = 0; i <= 100; i++) F[u][i] = pair<int, int>(1e9, -1e9);
  if (g[u].size() == 0) {
    F[u][0] = pair<int, int>(val[u], val[u]);
    return;
  }
  for (int i = 0; i < g[u].size(); i++)
    if (g[u][i] != root) FinalDFS(g[u][i], u);
  for (int i = 0; i <= 100; i++) F[u][i] = F[g[u][0]][i];
  for (int i = 1; i < g[u].size(); i++) {
    int v = g[u][i];
    for (int j = 0; j <= 100; j++) FF[j] = pair<int, int>(1e9, -1e9);
    for (int j = 0; j <= 100; j++)
      for (int jj = 0; jj <= j; jj++) {
        if (jj < j) {
          if (cplus <= 100) {
            FF[j].first =
                min(FF[j].first, F[u][j - jj - 1].first + F[v][jj].first);
            FF[j].second =
                max(FF[j].second, F[u][j - jj - 1].second + F[v][jj].second);
          } else {
            FF[j].first =
                min(FF[j].first, F[u][j - jj - 1].first - F[v][jj].second);
            FF[j].second =
                max(FF[j].second, F[u][j - jj - 1].second - F[v][jj].first);
          }
        }
        if (cplus <= 100) {
          FF[j].first = min(FF[j].first, F[u][j - jj].first - F[v][jj].second);
          FF[j].second =
              max(FF[j].second, F[u][j - jj].second - F[v][jj].first);
        } else {
          FF[j].first = min(FF[j].first, F[u][j - jj].first + F[v][jj].first);
          FF[j].second =
              max(FF[j].second, F[u][j - jj].second + F[v][jj].second);
        }
      }
    for (int j = 0; j <= 100; j++) F[u][j] = FF[j];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> s >> cplus >> cminus;
  DFS(0);
  FinalDFS(1, 1);
  if (cplus <= 100)
    cout << F[1][cplus].second;
  else
    cout << F[1][cminus].second;
}
