#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int nn = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long i, j, k, l, m, n, x = 0, y = 0, z = 0, e = 0, f = 0, g = 0, h = 0;
  string p, q, s;
  unordered_set<int> sw;
  unordered_map<int, int> mp;
  vector<int> u, v;
  cin >> s;
  cin >> k;
  n = s.size();
  for (i = 0; i < n; i++) {
    if (s[i] == '*') {
      x += 1;
    } else if (s[i] == '?') {
      y += 1;
    } else {
      p += s[i];
      z += 1;
    }
  }
  g = z - y - x;
  h = z;
  if (x > 0) {
    h = 2005;
  }
  if ((k > h) || (k < g)) {
    cout << "Impossible\n";
  } else {
    if (k == z) {
      cout << p << "\n";
    } else if (k < z) {
      l = z - k;
      for (i = 0; i < n; i++) {
        if (s[i] == '*') {
          if (l > 0) {
            q.pop_back();
            l -= 1;
          }
        } else if (s[i] == '?') {
          if (l > 0) {
            l -= 1;
            q.pop_back();
          }
        } else {
          q += s[i];
        }
      }
      cout << q << "\n";
    } else {
      l = k - z;
      h = 1;
      for (i = 0; i < n; i++) {
        if (s[i] == '*') {
          if (h) {
            m = q.size();
            m -= 1;
            while (l--) {
              q += q[m];
            }
            h = 0;
          }
        } else if (s[i] != '?') {
          q += s[i];
        }
      }
      cout << q << "\n";
    }
  }
}
