#include <bits/stdc++.h>
static const bool debug = 0;
using namespace std;
using ll = long long;
int MAXINT = 2e9;
ll MAXLL = 9e18;
int main() {
  {
    if (!debug) {
      ios::sync_with_stdio(0);
      cin.tie(0);
    }
    cout << setprecision(10) << fixed;
  };
  string a;
  cin >> a;
  int k;
  cin >> k;
  int extra = 0;
  for (int(i) = (0); (i) < (a.size()); ++(i)) {
    if (a[i] == '?' || a[i] == '*') extra++;
  }
  int real = a.size() - extra;
  reverse((a).begin(), (a).end());
  vector<char> ans;
  for (int(i) = (0); (i) < (a.size()); ++(i)) {
    if (a[i] != '?' && a[i] != '*') {
      ans.push_back(a[i]);
      continue;
    } else if (real > k) {
      real--;
      i++;
      continue;
    } else if (real < k && a[i] == '*') {
      for (int(u) = (0); (u) < (k - real); ++(u)) {
        ans.push_back(a[i + 1]);
      }
      real = k;
    } else {
      continue;
    }
  }
  reverse((ans).begin(), (ans).end());
  if (ans.size() == k) {
    for (auto a : ans) cout << a;
  } else
    cout << "Impossible";
}
