#include <bits/stdc++.h>
using namespace std;
vector<int> vec[2 * (int)1e4 + 15];
const int inf = (int)1e8;
int p, m, dp[2 * (int)1e4 + 15][100 + 5][2];
int dfs(int u, int op, int whatNeed) {
  if (vec[u].size() == 0) {
    if (op)
      return (!whatNeed) ? -inf : inf;
    else
      return u;
  }
  if (dp[u][op][whatNeed] != INT_MAX) return dp[u][op][whatNeed];
  int &ret = dp[u][op][whatNeed] = (!whatNeed) ? -inf : inf;
  if (!whatNeed) {
    if (p <= m) {
      for (int i = 0; i <= op; i++) {
        int ret1 = dfs(vec[u][0], i, 0);
        int ret2 = dfs(vec[u][1], op - i, 1);
        ret = max(ret, ret1 - ret2);
      }
      --op;
      for (int i = 0; i <= op; i++) {
        int ret3 = dfs(vec[u][0], i, 0);
        int ret4 = dfs(vec[u][1], op - i, 0);
        ret = max(ret, ret3 + ret4);
      }
    } else {
      for (int i = 0; i <= op; i++) {
        int ret1 = dfs(vec[u][0], i, 0);
        int ret2 = dfs(vec[u][1], op - i, 0);
        ret = max(ret, ret1 + ret2);
      }
      --op;
      for (int i = 0; i <= op; i++) {
        int ret3 = dfs(vec[u][0], i, 0);
        int ret4 = dfs(vec[u][1], op - i, 1);
        ret = max(ret, ret3 - ret4);
      }
    }
  } else {
    if (p <= m) {
      for (int i = 0; i <= op; i++) {
        int ret1 = dfs(vec[u][0], i, 1);
        int ret2 = dfs(vec[u][1], op - i, 0);
        ret = min(ret, ret1 - ret2);
      }
      --op;
      for (int i = 0; i <= op; i++) {
        int ret3 = dfs(vec[u][0], i, 1);
        int ret4 = dfs(vec[u][1], op - i, 1);
        ret = min(ret, ret3 + ret4);
      }
    } else {
      for (int i = 0; i <= op; i++) {
        int ret1 = dfs(vec[u][0], i, 1);
        int ret2 = dfs(vec[u][1], op - i, 1);
        ret = min(ret, ret1 + ret2);
      }
      --op;
      for (int i = 0; i <= op; i++) {
        int ret3 = dfs(vec[u][0], i, 1);
        int ret4 = dfs(vec[u][1], op - i, 0);
        ret = min(ret, ret3 - ret4);
      }
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  cin >> p >> m;
  if (s.size() == 1) {
    printf("%d\n", s[0] - 48);
    return 0;
  }
  stack<int> st;
  int node = 9;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(' || s[i] == '?') continue;
    if (s[i] == ')') {
      int r = st.top();
      st.pop();
      int l = st.top();
      st.pop();
      vec[++node].push_back(l);
      vec[node].push_back(r);
      st.push(node);
      continue;
    }
    st.push(s[i] - '0');
  }
  for (int i = 0; i < 2 * (int)1e4 + 15; i++) {
    for (int j = 0; j < 100 + 5; j++) {
      for (int k = 0; k < 2; k++) {
        dp[i][j][k] = INT_MAX;
      }
    }
  }
  printf("%d\n", dfs(node, min(p, m), 0));
  return 0;
}
