#include <bits/stdc++.h>
using namespace std;
string t;
int n;
void bla(int del, int inc) {
  string res = "";
  for (int k = 0; k < t.size(); k++) {
    if (k < t.size() - 1 and t[k + 1] == '?' and del > 0) {
      del--;
      k++;
      continue;
    }
    if (k < t.size() - 1 and t[k + 1] == '*' and inc > 0) {
      for (int j = 0; j < inc + 1; j++) res += t[k];
      inc = 0;
      k++;
      continue;
    }
    if (k < t.size() - 1 and t[k + 1] == '*' and del > 0) {
      del--;
      k++;
      continue;
    }
    if (t[k] != '?' and t[k] != '*') res += t[k];
  }
  if (res.size() == n)
    cout << res;
  else
    cout << "Impossible";
  return;
}
int main() {
  cin >> t;
  cin >> n;
  int can = 0;
  int snow = 0;
  for (int k = 0; k < t.size(); k++) {
    if (t[k] == '?') can++;
    if (t[k] == '*') snow++;
  }
  int lett = (int)t.size() - can - snow;
  if (lett > n) {
    bla(lett - n, 0);
  } else if (lett == n) {
    bla(0, 0);
  } else if (lett < n) {
    bla(0, n - lett);
  }
  return 0;
}
