#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int l = 0, snow = 0, candy = 0, k;
  cin >> k;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '*')
      snow++;
    else if (s[i] == '?')
      candy++;
    else
      l++;
  }
  if (k == l) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] != '?' && s[i] != '*') cout << s[i];
    }
    cout << endl;
  } else if (k > l) {
    if (!snow) {
      cout << "Impossible" << endl;
    } else {
      int j = 0;
      bool flag = false;
      for (int i = 0; i < s.size(); i++) {
        if (s[i] != '?' && s[i] != '*') cout << s[i];
        if (s[i] == '*' && !flag) {
          flag = true;
          for (int j = 0; j < (k - l); j++) {
            cout << s[i - 1];
          }
        }
      }
      cout << endl;
    }
  } else if (k < l) {
    if ((candy + snow) < (l - k)) {
      cout << "Impossible" << endl;
    } else {
      for (int i = 0; i < s.size(); i++) {
        if (l == k) {
          if (s[i] != '?' && s[i] != '*') cout << s[i];
        } else if (s[i] == '?' || s[i] == '*') {
          continue;
        } else if (s[i + 1] == '?' || s[i + 1] == '*') {
          l--;
          continue;
        } else {
          cout << s[i];
        }
      }
      cout << endl;
    }
  }
}
