#include <bits/stdc++.h>
constexpr const int inf = 1000000;
struct node {
  int size;
  int dpmax[105], dpmin[105];
  bool leaf;
  node *left, *right;
  node() : size(0), leaf(false), left(nullptr), right(nullptr) {
    for (int i = 0; i <= 100; ++i) {
      dpmax[i] = -inf;
      dpmin[i] = inf;
    }
  }
  explicit node(int value)
      : size(0), leaf(true), left(nullptr), right(nullptr) {
    for (int i = 0; i <= 100; ++i) {
      dpmax[i] = -inf;
      dpmin[i] = inf;
    }
    dpmax[0] = dpmin[0] = value;
  }
};
char expr[10005];
node* root;
void build_expr_tree(node*& now, int left, int right) {
  int len = right - left + 1;
  if (len == 1) {
    assert(isdigit(expr[left]));
    now = new node(expr[left] - '0');
  } else {
    assert(len >= 5);
    assert(expr[left] == '(' && expr[right] == ')');
    now = new node();
    int parcnt = 0;
    int oppos;
    for (oppos = left + 1; oppos < right; ++oppos) {
      if (expr[oppos] == '(')
        ++parcnt;
      else if (expr[oppos] == ')')
        --parcnt;
      else if (expr[oppos] == '?' && parcnt == 0)
        break;
    }
    assert(oppos < right);
    build_expr_tree(now->left, left + 1, oppos - 1);
    build_expr_tree(now->right, oppos + 1, right - 1);
    now->size = 1 + now->left->size + now->right->size;
  }
}
void maintain_plus(node* now) {
  for (int pc = 0; pc <= now->size && pc <= 100; ++pc) {
    for (int leftpc = 0; leftpc <= pc && leftpc <= now->left->size; ++leftpc) {
      if (pc > leftpc && pc - leftpc - 1 <= now->right->size) {
        now->dpmax[pc] =
            std::max(now->dpmax[pc], now->left->dpmax[leftpc] +
                                         now->right->dpmax[pc - leftpc - 1]);
        now->dpmin[pc] =
            std::min(now->dpmin[pc], now->left->dpmin[leftpc] +
                                         now->right->dpmin[pc - leftpc - 1]);
      }
      if (pc - leftpc <= now->right->size) {
        now->dpmax[pc] =
            std::max(now->dpmax[pc],
                     now->left->dpmax[leftpc] - now->right->dpmin[pc - leftpc]);
        now->dpmin[pc] =
            std::min(now->dpmin[pc],
                     now->left->dpmin[leftpc] - now->right->dpmax[pc - leftpc]);
      }
    }
  }
}
void maintain_minus(node* now) {
  for (int pm = 0; pm <= now->size && pm <= 100; ++pm) {
    for (int leftpm = 0; leftpm <= pm && leftpm <= now->left->size; ++leftpm) {
      if (pm > leftpm && pm - leftpm - 1 <= now->right->size) {
        now->dpmax[pm] =
            std::max(now->dpmax[pm], now->left->dpmax[leftpm] -
                                         now->right->dpmin[pm - leftpm - 1]);
        now->dpmin[pm] =
            std::min(now->dpmin[pm], now->left->dpmin[leftpm] -
                                         now->right->dpmax[pm - leftpm - 1]);
      }
      if (pm - leftpm <= now->right->size) {
        now->dpmax[pm] =
            std::max(now->dpmax[pm],
                     now->left->dpmax[leftpm] + now->right->dpmax[pm - leftpm]);
        now->dpmin[pm] =
            std::min(now->dpmin[pm],
                     now->left->dpmin[leftpm] + now->right->dpmin[pm - leftpm]);
      }
    }
  }
}
void dfs_solve(node* now, void (*const& maintainer)(node*)) {
  if (!now || now->leaf) return;
  dfs_solve(now->left, maintainer);
  dfs_solve(now->right, maintainer);
  maintainer(now);
}
int main(int argc, char* argv[]) {
  scanf("%s", expr);
  int p, m;
  scanf("%d%d", &p, &m);
  build_expr_tree(root, 0, strlen(expr) - 1);
  assert(p + m == root->size);
  dfs_solve(root, p <= m ? &maintain_plus : &maintain_minus);
  printf("%d\n", root->dpmax[std::min(p, m)]);
  return 0;
}
