#include <bits/stdc++.h>
char _;
using namespace std;
void PRINT(int x, int y) {
  for (int i = y - 1; i >= 0; i--) {
    cout << ((0u == (x & (1 << i))) ? 0u : 1u);
  }
  cout << endl;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int k, cnt = 0, star = 0, q = 0;
  cin >> k;
  for (int x = 0; x < ((int)s.length()); x++) {
    if (s[x] != '?' && s[x] != '*') {
      cnt++;
    }
    if (s[x] == '?') {
      q++;
    } else if (s[x] == '*') {
      star++;
    }
  }
  if (cnt == k) {
    for (int x = 0; x < ((int)s.length()); x++) {
      if (s[x] != '?' && s[x] != '*') {
        cout << s[x];
      }
    }
    cout << "\n";
  } else if (cnt < k) {
    if (star > 0) {
      bool done = false;
      int req = k - cnt;
      for (int x = 0; x < ((int)s.length()); x++) {
        if (!done && x < (int)s.length() - 1 && s[x + 1] == '*') {
          while (req--) {
            cout << s[x];
          }
          done = true;
        }
        if (s[x] != '*' && s[x] != '?') {
          cout << s[x];
        }
      }
      cout << "\n";
    } else {
      cout << "Impossible\n";
    }
  } else if (cnt > k) {
    if (q + star < cnt - k) {
      cout << "Impossible\n";
    } else {
      int rem = cnt - k;
      for (int x = 0; x < ((int)s.length()); x++) {
        if (rem > 0 && x < (int)s.length() - 1 &&
            (s[x + 1] == '*' || s[x + 1] == '?')) {
          rem--;
          continue;
        } else if (s[x] != '*' && s[x] != '?') {
          cout << s[x];
        }
      }
      cout << "\n";
    }
  }
}
