#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n;
  cin >> s >> n;
  int l = s.length();
  int a(0), q(0), m, x;
  char c;
  for (x = 0; x < l; x++) {
    if (s[x] == '?') {
      q++;
    }
    if (s[x] == '*') {
      a++;
    }
  }
  m = l - (q + a);
  string t;
  if (n > m) {
    if (a == 0) {
      cout << "Impossible" << endl;
      return 0;
    } else {
      for (x = 0; x < l; x++) {
        if (s[x] == '?') {
          continue;
        } else if (s[x] == '*') {
          c = s[x - 1];
          while (m != n) {
            t.push_back(c);
            m++;
          }
        } else {
          t.push_back(s[x]);
        }
      }
    }
  } else if (n < m) {
    if (n < (m - a - q)) {
      cout << "Impossible" << endl;
      return 0;
    } else {
      for (x = 0; x < l; x++) {
        if (s[x] == '?' || s[x] == '*') {
          if (n < m) {
            t.pop_back();
            m--;
          } else {
            continue;
          }
        } else {
          t.push_back(s[x]);
        }
      }
    }
  } else {
    for (x = 0; x < l; x++) {
      if (s[x] == '?' || s[x] == '*') {
        continue;
      } else {
        t.push_back(s[x]);
      }
    }
  }
  cout << t << endl;
  return 0;
}
