#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n, m = 0, i, j, p = 0, c = 0, len = s.length(), k = 0, r = 0, q = 0;
  cin >> n;
  for (i = 0; i < len; i++) {
    if (s[i] == '?') {
      p++;
    } else if (s[i] == '*') {
      k++;
    } else {
      c++;
    }
  }
  if (n == c) {
    for (i = 0; i < len; i++) {
      if (s[i] == '?' || s[i] == '*')
        continue;
      else
        cout << s[i];
    }
    cout << endl;
  } else if (n > c) {
    if (k >= 1) {
      for (i = 0; i < len; i++) {
        if (s[i] == '*') {
          r = i;
          break;
        }
      }
      for (i = 0; i < r; i++) {
        if (s[i] == '?')
          continue;
        else
          cout << s[i];
      }
      for (i = 0; i < n - c; i++) cout << s[r - 1];
      for (i = r; i < len; i++) {
        if (s[i] == '*' || s[i] == '?')
          continue;
        else
          cout << s[i];
      }
      cout << endl;
    } else
      cout << "Impossible" << endl;
  } else if (n < c) {
    if (p + k >= c - n) {
      for (i = 0; i < len; i++) {
        if (s[i] == '*' || s[i] == '?') {
          m++;
          if (m == c - n) {
            q = i;
            break;
          }
        }
      }
      for (i = 0; i <= q; i++) {
        if (s[i] == '*' || s[i] == '?') {
          s[i - 1] = '*';
        }
      }
      for (i = 0; i < len; i++) {
        if (s[i] == '*' || s[i] == '?')
          continue;
        else
          cout << s[i];
      }
    } else
      cout << "Impossible" << endl;
  }
}
