#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e4 + 50;
template <class t>
inline void read(t &s) {
  s = 0;
  register int f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  int buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool checkmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool checkmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline int lowbit(int x) { return x & (-x); }
int f[MaxN][105], g[MaxN][105], siz[MaxN], ndn, len, P, M;
char s[MaxN];
stack<int> S;
namespace PLESS {
inline void merge(int x, int y) {
  int t[105], q[105];
  memset(t, 0xc0, sizeof t), memset(q, 0x3f, sizeof q);
  for (int i = 0; i <= siz[x]; ++i)
    for (int j = 0; j <= siz[y] && i + j + 1 <= P; ++j)
      checkmax(t[i + j + 1], f[x][i] + f[y][j]),
          checkmin(q[i + j + 1], g[x][i] + g[y][j]);
  for (int i = 0; i <= siz[x]; ++i)
    for (int j = 0; j <= siz[y] && i + j <= P; ++j)
      checkmax(t[i + j], f[x][i] - g[y][j]),
          checkmin(q[i + j], g[x][i] - f[y][j]);
  siz[x] = min(P, siz[x] + siz[y] + 1);
  for (int i = 0; i <= siz[x]; ++i) f[x][i] = t[i], g[x][i] = q[i];
  return;
}
inline int NewNum(int x) {
  ++ndn;
  f[ndn][0] = g[ndn][0] = x;
  siz[ndn] = 0;
  return ndn;
}
inline signed main(void) {
  for (int i = 1; i <= len; ++i) {
    register char c = s[i];
    if (c == '(' || c == '?')
      S.push(c);
    else if (c == ')') {
      while (true) {
        register int y = S.top();
        S.pop();
        register int x = S.top();
        S.pop();
        if (x == '(') {
          S.push(y);
          break;
        } else {
          x = S.top();
          S.pop();
          merge(x, y);
          S.push(x);
        }
      }
    } else
      S.push(NewNum(c ^ 48));
  }
  write(f[S.top()][P]), puts("");
  return 0;
}
}  // namespace PLESS
namespace MLESS {
inline void merge(int x, int y) {
  int t[105], q[105];
  memset(t, 0xc0, sizeof t), memset(q, 0x3f, sizeof q);
  for (int i = 0; i <= siz[x]; ++i)
    for (int j = 0; j <= siz[y] && i + j <= M; ++j)
      checkmax(t[i + j], f[x][i] + f[y][j]),
          checkmin(q[i + j], g[x][i] + g[y][j]);
  for (int i = 0; i <= siz[x]; ++i)
    for (int j = 0; j <= siz[y] && i + j + 1 <= M; ++j)
      checkmax(t[i + j + 1], f[x][i] - g[y][j]),
          checkmin(q[i + j + 1], g[x][i] - f[y][j]);
  siz[x] = min(M, siz[x] + siz[y] + 1);
  for (int i = 0; i <= siz[x]; ++i) f[x][i] = t[i], g[x][i] = q[i];
  return;
}
inline int NewNum(int x) {
  ++ndn;
  f[ndn][0] = g[ndn][0] = x;
  siz[ndn] = 0;
  return ndn;
}
inline signed main(void) {
  for (int i = 1; i <= len; ++i) {
    register char c = s[i];
    if (c == '(' || c == '?')
      S.push(c);
    else if (c == ')') {
      while (true) {
        register int y = S.top();
        S.pop();
        register int x = S.top();
        S.pop();
        if (x == '(') {
          S.push(y);
          break;
        } else {
          x = S.top();
          S.pop();
          merge(x, y);
          S.push(x);
        }
      }
    } else
      S.push(NewNum(c ^ 48));
  }
  write(f[S.top()][M]), puts("");
  return 0;
}
}  // namespace MLESS
signed main(void) {
  scanf("%s", s + 1);
  len = strlen(s + 1);
  read(P, M);
  if (P <= 100)
    return PLESS::main();
  else
    return MLESS::main();
  return 0;
}
