#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> maxMap;
map<pair<int, int>, int> minMap;
struct Node {
  int id;
  int value;
  int count;
  Node* left;
  Node* right;
  Node() {
    count = 0;
    value = 0;
    left = right = NULL;
  }
};
int idn = 0;
void createTree(Node* root, string& str, int& idx) {
  root->id = idn;
  idn++;
  if (str[idx] != '(') {
    root->value = str[idx] - '0';
    root->count = 0;
    idx++;
    return;
  }
  idx++;
  root->left = new Node();
  createTree(root->left, str, idx);
  idx++;
  root->right = new Node();
  createTree(root->right, str, idx);
  idx++;
  root->count = ((root->left)->count) + ((root->right)->count) + 1;
}
void printTree(Node* root) {
  if (root == NULL) return;
  printTree(root->left);
  if (root->count)
    cout << root->count << endl;
  else
    cout << root->value << endl;
  printTree(root->right);
}
int rec(Node* root, int p, int curr) {
  int val = root->id;
  if (root->count == 0) {
    if (p == 0) return (root->value);
  }
  int n = (root->count) - p;
  if (curr == 1) {
    if (maxMap.find(make_pair(val, p)) != maxMap.end())
      return maxMap[make_pair(val, p)];
    int ans = INT_MIN;
    if (p > 0) {
      for (int x = max(0, p - 1 - (root->right->count));
           x <= min((p - 1), (root->left)->count); x++) {
        int ans1 = rec(root->left, x, curr);
        int ans2 = rec(root->right, (p - 1) - x, curr);
        ans = max(ans, ans1 + ans2);
      }
    }
    if (n > 0) {
      for (int x = max(0, p - (root->right->count));
           x <= min((p), (root->left)->count); x++) {
        int ans1 = rec(root->left, x, curr);
        int ans2 = rec(root->right, p - x, -1 * curr);
        ans = max(ans, ans1 - ans2);
      }
    }
    maxMap[make_pair(val, p)] = ans;
    return ans;
  } else {
    if (minMap.find(make_pair(val, p)) != minMap.end())
      return minMap[make_pair(val, p)];
    int ans = INT_MAX;
    if (p > 0) {
      for (int x = x = max(0, p - 1 - (root->right->count));
           x <= min((p - 1), (root->left)->count); x++) {
        int ans1 = rec(root->left, x, curr);
        int ans2 = rec(root->right, (p - 1) - x, curr);
        ans = min(ans, ans1 + ans2);
      }
    }
    if (n > 0) {
      for (int x = x = max(0, p - (root->right->count));
           x <= min((p), (root->left)->count); x++) {
        int ans1 = rec(root->left, x, curr);
        int ans2 = rec(root->right, p - x, -1 * curr);
        ans = min(ans, ans1 - ans2);
      }
    }
    minMap[make_pair(val, p)] = ans;
    return ans;
  }
}
int main() {
  idn = 0;
  string str;
  cin >> str;
  int n1, n2;
  cin >> n1 >> n2;
  if (str.size() == 1) {
    cout << str << endl;
    return 0;
  }
  maxMap.clear();
  minMap.clear();
  Node* root = new Node();
  int idx = 0;
  createTree(root, str, idx);
  int ans = rec(root, n1, 1);
  cout << ans << endl;
  return 0;
}
