#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int k;
  cin >> k;
  int l = str.length();
  int actlength = 0;
  for (int i = 0; i < l; i++) {
    if (str.at(i) != '?' && str.at(i) != '*') {
      actlength++;
    }
  }
  string ans = "";
  if (k == actlength) {
    for (int i = 0; i < l; i++) {
      if (str.at(i) != '?' && str.at(i) != '*') {
        ans = ans + str.at(i);
      }
    }
    cout << ans << endl;
  } else if (k < actlength) {
    int x = actlength - k;
    int y = 0;
    int j = 0;
    while (x != 0 && j < l - 1) {
      if (str.at(j + 1) != '?' && str.at(j + 1) != '*' && str.at(j) != '?' &&
          str.at(j) != '*') {
        ans = ans + str.at(j);
        y++;
      } else if (str.at(j + 1) != '?' && str.at(j + 1) != '*')
        x--;
      j++;
    }
    while (j < l) {
      if (str.at(j) != '?' && str.at(j) != '*') {
        ans = ans + str.at(j);
        y++;
      }
      j++;
    }
    if (y == k) {
      cout << ans << endl;
    } else
      cout << "Impossible" << endl;
  } else {
    int diff = k - actlength;
    int z = 0;
    int p = 0;
    for (int i = 0; i < l; i++) {
      if (str.at(i) != '?' && str.at(i) != '*') {
        ans = ans + str.at(i);
        z++;
      }
      if (str.at(i) == '*' && p != diff) {
        while (p < diff) {
          ans = ans + str.at(i - 1);
          p++;
          z++;
        }
      }
    }
    if (z == k) {
      cout << ans << endl;
    } else
      cout << "Impossible" << endl;
  }
  return 0;
}
