#include <bits/stdc++.h>
using namespace std;
using namespace std;
int arr[26];
int mark(int loc) {
  while (arr[loc] != loc) {
    loc = arr[loc];
  }
  return loc;
}
void SieveOfErat() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= 1000000; p++) {
    if (prime[p] == true) {
      for (long long i = p * 2; i <= 1000000; i += p) prime[i] = false;
    }
  }
}
long long var = -1000000;
long long util[10005];
long long ct[10005];
long long tot[10005];
long long fi1[10005][101];
long long fi2[10005][101];
string e;
bool plus1 = false;
void calc(long long i, long long op) {
  long long j = util[i];
  long long len = (j - i) + 1;
  if (len == 1) {
    fi1[i][op] = e[i] - '0';
    fi2[i][op] = e[i] - '0';
    return;
  }
  fi1[i][op] = -10000005;
  fi2[i][op] = 10000005;
  long long temp[2];
  for (long long k = 0; k <= op; k++) {
    if (k > tot[i + 1] || (op - k) > tot[util[i + 1] + 2]) continue;
    if (fi1[i + 1][k] == var) calc(i + 1, k);
    if (fi1[util[i + 1] + 2][op - k] == var) calc(util[i + 1] + 2, op - k);
    if (plus1)
      temp[0] = fi1[i + 1][k] - fi2[util[i + 1] + 2][op - k];
    else
      temp[0] = fi1[i + 1][k] + fi1[util[i + 1] + 2][op - k];
    if (plus1)
      temp[1] = fi2[i + 1][k] - fi1[util[i + 1] + 2][op - k];
    else
      temp[1] = fi2[i + 1][k] + fi2[util[i + 1] + 2][op - k];
    fi1[i][op] = max(fi1[i][op], temp[0]);
    fi2[i][op] = min(fi2[i][op], temp[1]);
  }
  if (op != 0) {
    op--;
    for (long long k = 0; k <= op; k++) {
      if (k > tot[i + 1] || (op - k) > tot[util[i + 1] + 2]) continue;
      if (fi1[i + 1][k] == var) calc(i + 1, k);
      if (fi1[util[i + 1] + 2][op - k] == var) calc(util[i + 1] + 2, op - k);
      if (plus1)
        temp[0] = fi1[i + 1][k] + fi1[util[i + 1] + 2][op - k];
      else
        temp[0] = fi1[i + 1][k] - fi2[util[i + 1] + 2][op - k];
      if (plus1)
        temp[1] = fi2[i + 1][k] + fi2[util[i + 1] + 2][op - k];
      else
        temp[1] = fi2[i + 1][k] - fi1[util[i + 1] + 2][op - k];
      fi1[i][op + 1] = max(fi1[i][op + 1], temp[0]);
      fi2[i][op + 1] = min(fi2[i][op + 1], temp[1]);
    }
    op++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> e;
  long long p, m;
  cin >> p >> m;
  long long n = (long long)(e.length());
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j <= min(p, m); j++) {
      fi1[i][j] = var;
      fi2[i][j] = var;
    }
  }
  stack<long long> st;
  for (long long i = 0; i < n; i++) {
    if (e[i] == '(')
      st.push(i);
    else if (e[i] == ')') {
      long long temp = st.top();
      st.pop();
      util[temp] = i;
      util[i] = temp;
    } else {
      util[i] = i;
    }
    if (i == 0)
      ct[i] = 0;
    else
      ct[i] = ct[i - 1];
    if (e[i] == '?') ct[i]++;
  }
  for (long long i = 0; i < n; i++) {
    tot[i] = ct[util[i]];
    if (i != 0) {
      tot[i] -= ct[i - 1];
    }
  }
  if (p < m) plus1 = true;
  calc(0, min(p, m));
  cout << fi1[0][min(p, m)] << endl;
  return 0;
}
