#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int k;
  cin >> k;
  char char_arr[500];
  strcpy(char_arr, s.c_str());
  vector<char> vec;
  int val = 0;
  for (int i = 0; i < s.length(); i++) {
    if (char_arr[i] != '?' && char_arr[i] != '*') val++;
  }
  int count = k - val;
  int flag = 0, nf = 0;
  int parth = 0, g = 0;
  if (val == k) {
    for (int i = 0; i < s.length(); i++) {
      if (char_arr[i] != '?' && char_arr[i] != '*') vec.push_back(char_arr[i]);
    }
  } else if (val < k) {
    for (int i = 0; i < s.length(); i++) {
      if (char_arr[i] == '*') {
        nf = 1;
      }
    }
    if (nf == 0) {
      cout << "Impossible\n";
      return 0;
    }
    for (int i = 0; i < s.length(); i++) {
      if (char_arr[i] == '?') {
        parth++;
      } else if (char_arr[i] == '*') {
        char c = vec.back();
        while (flag < count) {
          vec.push_back(c);
          flag++;
        }
      } else
        vec.push_back(char_arr[i]);
    }
  } else {
    for (int i = 0; i < s.length(); i++) {
      if (char_arr[i] == '?' || char_arr[i] == '*') g++;
    }
    if (val - g > k) {
      cout << "Impossible\n";
      return 0;
    }
    for (int i = 0; i < s.length(); i++) {
      if (char_arr[i] == '?') {
        if (count < 0) {
          vec.pop_back();
          count++;
        }
      } else if (char_arr[i] == '*') {
        if (count < 0) {
          vec.pop_back();
          count++;
        }
      } else
        vec.push_back(char_arr[i]);
    }
  }
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i] != '*' && vec[i] != '?') cout << vec[i];
  }
  cout << endl;
  return 0;
}
