#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void mad(long long &a, long long b) {
  a = (a + b) % 1000000007;
  if (a < 0) a += 1000000007;
}
long long gcd(long long a, long long b) {
  if (!a) return b;
  return gcd(b % a, a);
}
pair<int, int> dp[10005][105];
int st[10005], lt[10005], rt[10005];
string s;
int mk;
void build(int i, int l, int r) {
  if (l == r) {
    st[i] = s[l] - '0';
    return;
  }
  int cur = 0;
  int j = l + 1;
  for (j = l + 1; j < r; j++) {
    if (s[j] == '(')
      cur++;
    else if (s[j] == ')')
      cur--;
    if (cur == 0) break;
  }
  lt[i] = l + 1;
  rt[i] = j + 2;
  build(lt[i], l + 1, j);
  build(rt[i], j + 2, r - 1);
}
pair<int, int> rec(int i, int p) {
  if (st[i]) {
    if (p) return pair<int, int>(1e9, -1e9);
    return pair<int, int>(st[i], st[i]);
  }
  if (dp[i][p].first != -1) return dp[i][p];
  int mini = 1e9, maxi = -1e9;
  if (mk) {
    pair<int, int> a, b;
    for (int l = 0; l < p; l++) {
      a = rec(lt[i], l);
      b = rec(rt[i], p - l - 1);
      mini = min(mini, a.first + b.first);
      maxi = max(maxi, a.second + b.second);
    }
    for (int l = 0; l <= p; l++) {
      a = rec(lt[i], l);
      b = rec(rt[i], p - l);
      mini = min(mini, a.first - b.second);
      maxi = max(maxi, a.second - b.first);
    }
  } else {
    pair<int, int> a, b;
    for (int l = 0; l <= p; l++) {
      a = rec(lt[i], l);
      b = rec(rt[i], p - l);
      mini = min(mini, a.first + b.first);
      maxi = max(maxi, a.second + b.second);
    }
    for (int l = 0; l < p; l++) {
      a = rec(lt[i], l);
      b = rec(rt[i], p - l - 1);
      mini = min(mini, a.first - b.second);
      maxi = max(maxi, a.second - b.first);
    }
  }
  return dp[i][p] = pair<int, int>(mini, maxi);
}
void solve() {
  cin >> s;
  int p, m;
  cin >> p >> m;
  if (p < m) mk = 1;
  for (int i = 0; i < 10005; i++)
    for (int j = 0; j <= min(m, p); j++) dp[i][j] = make_pair(-1, -1);
  int n = s.length();
  build(0, 0, n - 1);
  pair<int, int> ans = rec(0, min(m, p));
  cout << ans.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
