#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s2;
  int n, i, j, a, k;
  cin >> s;
  cin >> n;
  a = 0;
  for (i = 0; i < s.length(); i++) {
    if (s[i] == '?' || s[i] == '*')
      continue;
    else
      a++;
  }
  if (a == n) {
    for (i = 0; i < s.length(); i++) {
      if (s[i] == '?' || s[i] == '*')
        continue;
      else
        s2.push_back(s[i]);
    }
  }
  if (a < n) {
    int b = n - a;
    for (i = 0; i < s.length(); i++) {
      if (s[i] == '?')
        continue;
      else if (s[i] == '*') {
        for (j = 0; j < b; j++) {
          s2.push_back(s[i - 1]);
        }
        b = 0;
      } else
        s2.push_back(s[i]);
    }
  }
  if (a > n) {
    s.push_back('#');
    k = a - n;
    for (i = 0; i < s.length() - 1; i++) {
      if ((s[i + 1] == '?' || s[i + 1] == '*') && k > 0) {
        k--;
        continue;
      } else if ((s[i] == '?' || s[i] == '*'))
        continue;
      else
        s2.push_back(s[i]);
    }
  }
  if (s2.length() != n)
    cout << "Impossible";
  else {
    cout << s2;
  }
  return 0;
}
