#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2>& p) {
  out << p.first << ' ' << p.second;
}
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
  for (auto& x : v) in >> x;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
  for (auto x : v) out << x << ' ';
  return out;
}
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  string s;
  cin >> s;
  long long int n;
  cin >> n;
  string s1 = "";
  for (long long i = (0); i < ((long long int)s.size()); ++i) {
    if (s[i] != '*' && s[i] != '?') s1 += s[i];
  }
  if ((long long int)s1.size() == n) {
    cout << s1;
    exit(0);
  }
  string ans = "";
  if ((long long int)s1.size() < n) {
    bool f = 0;
    for (long long i = (0); i < ((long long int)s.size()); ++i) {
      if (s[i] != '*' && s[i] != '?') ans += s[i];
      if (s[i] == '*' && f == 0) {
        f = 1;
        for (long long j = (0); j < (n - (long long int)s1.size()); ++j) {
          ans += s[i - 1];
        }
      }
    }
    if (f)
      cout << ans;
    else
      cout << "Impossible";
    exit(0);
  }
  if ((long long int)s1.size() > n) {
    bool f = 0;
    long long int cnt = 0;
    for (long long i = (0); i < ((long long int)s.size()); ++i) {
      if (i < (long long int)s.size() - 1 &&
          (s[i + 1] == '*' || s[i + 1] == '?') &&
          cnt < abs(n - (long long int)s1.size())) {
        cnt++;
      } else if (s[i] != '*' && s[i] != '?')
        ans += s[i];
    }
    if (cnt == abs(n - (long long int)s1.size()))
      cout << ans;
    else
      cout << "Impossible";
    exit(0);
  }
}
