#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
string s;
int v[10010];
int tr[40010];
vector<int> g[10010];
int folha[10010];
int n;
void parse() {
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      cnt++;
    else if (s[i] == ')')
      cnt--;
    else if (s[i] == '+' or s[i] == '-' or s[i] == '?')
      v[i] = cnt;
    else
      v[i] = INF - 1, folha[i] = 1;
  }
}
void build(int node, int b, int e) {
  if (b == e)
    tr[node] = b;
  else {
    int mid = (b + e) / 2;
    build(2 * node, b, mid);
    build(2 * node + 1, mid + 1, e);
    tr[node] = (v[tr[2 * node]] < v[tr[2 * node + 1]]) ? tr[2 * node]
                                                       : tr[2 * node + 1];
  }
}
int query(int node, int b, int e, int i, int j) {
  if (e < i or j < b) return -1;
  if (i <= b and j >= e) return tr[node];
  int mid = (b + e) / 2;
  int p1 = query(2 * node, b, mid, i, j);
  int p2 = query(2 * node + 1, mid + 1, e, i, j);
  if (p1 == -1) return p2;
  if (p2 == -1) return p1;
  return (v[p1] < v[p2]) ? p1 : p2;
}
int build_graph(int i, int j) {
  int menor = query(1, 0, n - 1, i, j);
  if (menor == -1 or v[menor] == INF) return -1;
  int p1 = build_graph(i, menor - 1);
  int p2 = build_graph(menor + 1, j);
  if (p1 != -1) g[menor].push_back(p1);
  if (p2 != -2) g[menor].push_back(p2);
  return menor;
}
int dp[10010][110][2];
int sobrou;
int solve(int node, int op, int maxi) {
  if (folha[node]) {
    if (op == 0) {
      return s[node] - '0';
    }
    return INF;
  }
  assert(g[node].size() == 2);
  if (dp[node][op][maxi] != -1) return dp[node][op][maxi];
  int ret;
  if (s[node] == '+') {
    int p1 = solve(g[node][0], op, maxi);
    int p2 = solve(g[node][1], op, maxi);
    if (p1 != INF and p2 != INF) ret = p1 + p2;
  } else if (s[node] == '-') {
    int p1 = solve(g[node][0], op, maxi);
    int p2 = solve(g[node][1], op, !maxi);
    if (p1 != INF and p2 != INF) ret = p1 - p2;
  } else {
    if (maxi) {
      ret = -INF;
      for (int i = 0; i < op; i++) {
        int p1 = solve(g[node][0], i, maxi);
        int p2 = solve(g[node][1], op - 1 - i, maxi);
        int p3 = solve(g[node][1], op - 1 - i, 0);
        if (p1 != INF and p2 != INF) {
          ret = max(ret, p1 - sobrou * p2);
          ret = max(ret, p1 - sobrou * p3);
        }
      }
      for (int i = 0; i <= op; i++) {
        int p1 = solve(g[node][0], i, maxi);
        int p2 = solve(g[node][1], op - i, maxi);
        int p3 = solve(g[node][1], op - i, 0);
        if (p1 != INF and p2 != INF) {
          ret = max(ret, p1 + sobrou * p2);
          ret = max(ret, p1 + sobrou * p3);
        }
      }
      if (ret == -INF) ret = INF;
    } else {
      ret = INF;
      for (int i = 0; i < op; i++) {
        int p1 = solve(g[node][0], i, 0);
        int p2 = solve(g[node][1], op - 1 - i, 1);
        int p3 = solve(g[node][1], op - 1 - i, 0);
        if (p1 != INF and p2 != INF) {
          ret = min(ret, p1 - sobrou * p2);
          ret = min(ret, p1 - sobrou * p3);
        }
      }
      for (int i = 0; i <= op; i++) {
        int p1 = solve(g[node][0], i, 0);
        int p2 = solve(g[node][1], op - i, 1);
        int p3 = solve(g[node][1], op - i, 0);
        if (p1 != INF and p2 != INF) {
          ret = min(ret, p1 + sobrou * p2);
          ret = min(ret, p1 + sobrou * p3);
        }
      }
    }
  }
  return dp[node][op][maxi] = ret;
}
int main() {
  memset(v, INF, sizeof(v));
  memset(dp, -1, sizeof(dp));
  cin >> s;
  n = s.size();
  int mais, menos;
  cin >> mais >> menos;
  parse();
  build(1, 0, n - 1);
  if (mais > menos)
    sobrou = 1;
  else
    sobrou = -1;
  printf("%d\n", solve(build_graph(0, n - 1), min(mais, menos), 1));
  return 0;
}
