#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int min_letters = 0;
  bool multiple_letters = false;
  int variable_letters = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] != '*' && s[i] != '?') {
      min_letters++;
    } else {
      if (s[i] == '*') {
        multiple_letters = true;
      }
      variable_letters++;
      min_letters--;
    }
  }
  if (min_letters > k) {
    cout << "Impossible" << endl;
    return 0;
  } else if (!multiple_letters && k > (min_letters + variable_letters)) {
    cout << "Impossible" << endl;
    return 0;
  } else if (k == (min_letters + variable_letters)) {
    for (int i = 0; i < s.length(); ++i) {
      if (s[i] == '?' || s[i] == '*') continue;
      cout << s[i];
    }
  } else if (k < (min_letters + variable_letters)) {
    int allowed = k - min_letters;
    for (int i = 0; i < s.length(); ++i) {
      if (s[i] == '?' || s[i] == '*') continue;
      if (s[i + 1] != '?' && s[i + 1] != '*') {
        cout << s[i];
      } else {
        if (allowed) {
          cout << s[i];
          allowed--;
        }
      }
    }
  } else {
    int extra = k - (min_letters + variable_letters);
    for (int i = 0; i < s.length(); ++i) {
      if (s[i] == '?' || s[i] == '*') continue;
      if (s[i + 1] == '?') {
        cout << s[i];
      } else if (s[i + 1] == '*') {
        cout << s[i];
        while (extra) {
          cout << s[i];
          extra--;
        }
      } else {
        cout << s[i];
      }
    }
  }
  cout << endl;
}
