#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
void f() {
  cout << "Impossible\n";
  exit(0);
}
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int flake = 0, candy = 0;
  for (int i = 1; i < s.length(); i++) {
    if (s[i] == '*') flake++;
    if (s[i] == '?') candy++;
  }
  int check = 0;
  if (s[0] == '*' || s[0] == '?') check = 1;
  if (k < (s.length() - flake - flake - candy - candy - check)) {
    f();
  }
  if (flake == 0 && k > s.length() - candy - check) {
    f();
  }
  int count = s.length() - candy - candy - check - flake;
  int diff = k - count;
  if (diff < 0) {
    diff *= -1;
    string ans;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '?') {
        if (ans.length()) ans.pop_back();
        continue;
      }
      if (s[i] == '*' && diff && i) {
        if (ans.length()) {
          diff--;
          ans.pop_back();
        }
      }
      if (s[i] != '*' || s[i] == '?') ans += s[i];
    }
    cout << ans << "\n";
    return 0;
  }
  string ans;
  if (flake) {
    bool used = false;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '?') {
        if (ans.length()) ans.pop_back();
        continue;
      }
      if (s[i] == '*' && !used && i) {
        for (int j = 0; j < diff; j++) ans += s[i - 1];
        used = true;
      }
      if (s[i] != '*') ans += s[i];
    }
    cout << ans << "\n";
  } else {
    for (int i = 0; i < s.length(); i++) {
      if (i && s[i] == '?') {
        if (diff > 0) {
          diff--;
        } else
          ans.pop_back();
      }
      if (s[i] != '?') ans += s[i];
    }
    cout << ans << "\n";
  }
  return 0;
}
