#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0;
  T x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
struct Node {
  int sz, l, h;
};
Node x[10000];
pair<int, int> dp[10000][128];
int p, m, wmin, wmax;
bool use_p;
pair<int, int> add(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, int> sub(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(a.first - b.second, a.second - b.first);
}
void relax(pair<int, int> &d, const pair<int, int> &s) {
  d.first = min(d.first, s.first);
  d.second = max(d.second, s.second);
}
const char *solve(const char *str, int u = 0) {
  char c = *(str++);
  if (c >= '0' && c <= '9') {
    x[u] = {0, 0, 0};
    dp[u][0] = {c - '0', c - '0'};
    return str;
  }
  int a = u + 1, b = u + 2;
  str = solve(str, a);
  ++str;
  str = solve(str, b);
  ++str;
  x[u].sz = x[a].sz + x[b].sz;
  x[u].l = max(x[a].l + x[b].l, x[u].sz - wmax);
  x[u].h = min(x[a].h + x[b].h + 1, wmin);
  fill(dp[u] + x[u].l, dp[u] + x[u].h + 1, make_pair(999999999, -999999999));
  for (int ja = x[a].l; ja <= x[a].h; ++ja) {
    for (int jb = x[b].l; jb <= x[b].h; ++jb) {
      int jr = ja + jb;
      if (jr < x[u].l) continue;
      if (jr > x[u].h) break;
      pair<int, int> s = add(dp[a][ja], dp[b][jb]);
      pair<int, int> d = sub(dp[a][ja], dp[b][jb]);
      relax(dp[u][jr + use_p], s);
      relax(dp[u][jr + !use_p], d);
    }
  }
  return str;
}
int main() {
  canhazfast();
  static char s[10000 + 16];
  cin >> s >> p >> m;
  use_p = (p <= m);
  tie(wmin, wmax) = minmax(p, m);
  solve(s);
  cout << dp[0][wmin].second << '\n';
  return 0;
}
