#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int SIZE = 1e4 + 100;
constexpr int inf = 1e8;
vector<int> edge[SIZE];
int d[SIZE];
int s[SIZE];
map<int, map<int, map<int, int>>> mm;
int idx;
int build(const string &t, int l, int r) {
  if (l >= r) {
    return 0;
  }
  if (l == r - 1) {
    s[idx] = 0;
    d[idx++] = t[l] - '0';
    return 0;
  }
  int cnt = 0;
  int result = 1;
  int dirty = rand() & 1;
  if (dirty) {
    for (int i = l; i < r; i++) {
      if (t[i] == '(') cnt--;
      if (t[i] == ')') cnt++;
      if (t[i] == '?' && cnt == -1) {
        int myIdx = idx;
        d[myIdx] = -1;
        edge[myIdx].push_back(++idx);
        result += build(t, l + 1, i);
        edge[myIdx].push_back(idx);
        result += build(t, i + 1, r - 1);
        s[myIdx] = result;
        return result;
      }
    }
  } else {
    for (int i = r - 1; i >= l; i--) {
      if (t[i] == '(') cnt++;
      if (t[i] == ')') cnt--;
      if (t[i] == '?' && cnt == -1) {
        int myIdx = idx;
        d[myIdx] = -1;
        edge[myIdx].push_back(++idx);
        result += build(t, l + 1, i);
        edge[myIdx].push_back(idx);
        result += build(t, i + 1, r - 1);
        s[myIdx] = result;
        return result;
      }
    }
  }
  return 0;
}
int computePP(int v, int p, int type) {
  if (mm[p][type].count(v) != 0) {
    return mm[p][type][v];
  }
  if (d[v] != -1) {
    return d[v];
  }
  int left = edge[v][0];
  int right = edge[v][1];
  int best = -inf;
  if (type == 0) {
    best = inf;
    if (p > 0) {
      p--;
      for (int i = 0; i <= min(s[left], p); i++) {
        if (p - i <= s[right])
          best = min(best, computePP(left, i, 0) + computePP(right, p - i, 0));
      }
      p++;
    }
    if (s[v] > p) {
      for (int i = 0; i <= min(s[left], p); i++) {
        if (p - i <= s[right])
          best = min(best, computePP(left, i, 0) - computePP(right, p - i, 1));
      }
    }
  } else {
    if (p > 0) {
      p--;
      for (int i = 0; i <= min(s[left], p); i++) {
        if (p - i <= s[right])
          best = max(best, computePP(left, i, 1) + computePP(right, p - i, 1));
      }
      p++;
    }
    if (s[v] > p) {
      for (int i = 0; i <= min(s[left], p); i++) {
        if (p - i <= s[right])
          best = max(best, computePP(left, i, 1) - computePP(right, p - i, 0));
      }
    }
  }
  mm[p][type][v] = best;
  return mm[p][type][v];
}
int computeMM(int v, int m, int type) {
  if (mm[m][type].count(v) != 0) {
    return mm[m][type][v];
  }
  if (d[v] != -1) {
    return d[v];
  }
  int left = edge[v][0];
  int right = edge[v][1];
  int best = -inf;
  if (type == 0) {
    best = inf;
    if (m > 0) {
      m--;
      for (int i = 0; i <= min(s[left], m); i++) {
        if (m - i <= s[right])
          best = min(best, computeMM(left, i, 0) - computeMM(right, m - i, 1));
      }
      m++;
    }
    if (s[v] > m) {
      for (int i = 0; i <= min(s[left], m); i++) {
        if (m - i <= s[right])
          best = min(best, computeMM(left, i, 0) + computeMM(right, m - i, 0));
      }
    }
  } else {
    if (m > 0) {
      m--;
      for (int i = 0; i <= min(s[left], m); i++) {
        if (m - i <= s[right])
          best = max(best, computeMM(left, i, 1) - computeMM(right, m - i, 0));
      }
      m++;
    }
    if (s[v] > m) {
      for (int i = 0; i <= min(s[left], m); i++) {
        if (m - i <= s[right])
          best = max(best, computeMM(left, i, 1) + computeMM(right, m - i, 1));
      }
    }
  }
  mm[m][type][v] = best;
  return mm[m][type][v];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(std::time(nullptr));
  string t;
  cin >> t;
  if (t.length() == 1) {
    cout << t << "\n";
    return 0;
  }
  int p, m;
  cin >> p >> m;
  build(t, 0, t.size());
  if (p < m) {
    cout << computePP(0, p, 1) << "\n";
  } else {
    cout << computeMM(0, m, 1) << "\n";
  }
}
