#include <bits/stdc++.h>
using namespace std;
int n, zz, hold, cnt, cnt1, cnt2;
string s;
bool t = 0;
int main() {
  cin >> s >> n;
  int z = s.size();
  for (int i = 0; i < z; ++i) {
    if (s[i] == '?') cnt1++;
    if (s[i] == '*') cnt2++;
  }
  cnt = cnt1 + cnt2;
  if (z - (2 * cnt) > n || (z - cnt1 < n && !cnt2)) {
    cout << "Impossible";
    return 0;
  }
  if (z - cnt <= n) {
    zz = n - (z - cnt);
    for (int i = 0; i < z; ++i) {
      if (s[i] == '?') continue;
      if (s[i] == '*' && t) continue;
      if (s[i] == '*' && !t) {
        t = 1;
        for (int j = 0; j < zz; ++j) cout << s[i - 1];
        continue;
      }
      cout << s[i];
    }
  } else {
    zz = z - n - cnt;
    for (int i = 0; i < z; ++i) {
      if ((s[i] == '*' || s[i] == '?') && !t) {
        s[i - 1] = '#';
        s[i] = '#';
        hold++;
      }
      if ((s[i] == '*' || s[i] == '?') && t) {
        s[i] = '#';
        hold++;
      }
      if (hold == zz) t = 1;
    }
    for (int i = 0; i < z; ++i) {
      if (s[i] == '*' || s[i] == '#' || s[i] == '?') continue;
      cout << s[i];
    }
  }
  return 0;
}
