#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main() {
  string s;
  cin >> s;
  int n = s.length();
  string p = "";
  int sn = 0, c = 0;
  int x = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '*') {
      sn++;
    } else if (s[i] == '?') {
      c++;
    } else {
      x++;
    }
  }
  int k;
  cin >> k;
  if ((x - sn - c) > k) {
    cout << "Impossible" << '\n';
    return 0;
  }
  if (sn == 0 && x < k) {
    cout << "Impossible" << '\n';
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    if (s[i + 1] == '*' || s[i + 1] == '?') {
      i++;
      continue;
    }
    p += s[i];
  }
  if (s[n - 1] != '*' && s[n - 1] != '?') {
    p += s[n - 1];
  }
  string ans = "";
  if (x >= k) {
    int t = x - k;
    for (int i = 0; i < n - 1; i++) {
      if (s[i + 1] == '*' || s[i + 1] == '?') {
        if (t != 0) {
          t--;
          i++;
          continue;
        }
        ans += s[i];
        i++;
        continue;
      }
      ans += s[i];
    }
    if (s[n - 1] != '?' && s[n - 1] != '*') {
      ans += s[s.length() - 1];
    }
  } else {
    int l = 0;
    x = p.length();
    for (int i = 0; i < n - 1; i++) {
      if (s[i + 1] == '*' || s[i + 1] == '?') {
        if (s[i + 1] == '*') {
          while (x != k) {
            ans += s[i];
            x++;
          }
          for (int j = l; j < p.length(); j++) {
            ans += p[j];
          }
          break;
        }
        i++;
        continue;
      }
      ans += p[l];
      l++;
    }
  }
  cout << ans << '\n';
}
