#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int len, star = 0, question = 0, k = 0, n = 0;
  cin >> s;
  cin >> k;
  len = s.length();
  for (int i = 0; i < len; i++) {
    if (s[i] == '?') {
      question++;
    }
    if (s[i] == '*') {
      star++;
    }
  }
  n = len - (star + question);
  if (n == k) {
    for (int i = 0; i < len; i++) {
      if (s[i] != '?' && s[i] != '*') {
        cout << s[i];
      }
    }
  } else if (n < k && star < 1) {
    cout << "Impossible";
  } else if (n > k && n - star - question > k) {
    cout << "Impossible";
  } else {
    if (n > k) {
      for (int i = 0; i < len; i++) {
        if (s[i] != '?' && s[i] != '*') {
          if (i + 1 < len && (s[i + 1] == '?' || s[i + 1] == '*') && n > k) {
            n--;
          } else {
            cout << s[i];
          }
        }
      }
    } else {
      for (int i = 0; i < len; i++) {
        if (s[i] != '?' && s[i] != '*') {
          if (i + 1 < len && s[i + 1] == '*') {
            cout << s[i];
            while (n < k) {
              cout << s[i];
              n++;
            }
          } else {
            cout << s[i];
          }
        }
      }
    }
  }
  return 0;
}
