#include <bits/stdc++.h>
using namespace std;
inline long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
template <class T>
inline void read(T &x) {
  register char c = getchar();
  int neg = 0;
  x = 0;
  for (; (c < 48 || c > 57) && (c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline long long inversemod(long long a, long long M) {
  return bigmod(a, M - 2, M);
}
inline long long gcd(long long a, long long b) {
  while (b > 0) {
    a = a % b;
    {
      (a) ^= (b);
      (b) ^= (a);
      (a) ^= (b);
    };
  }
  return a;
}
inline long long lcm(long long m, long long n) { return m * n / gcd(m, n); }
class Runtime {
  double s, e;

 public:
  Runtime() { s = clock(); }
  ~Runtime() {
    e = clock();
    fprintf(stderr, "%lf s\n", (e - s) / CLOCKS_PER_SEC);
  }
};
Runtime t;
int main() {
  char str[222];
  int c = 0, s = 0, t, l = 0;
  cin >> str;
  cin >> t;
  int len = strlen(str);
  for (int i = 0; i < len; i++) {
    if (str[i] == '?')
      c++;
    else if (str[i] == '*')
      s++;
    else
      l++;
  }
  if (t == l)
    for (int i = 0; i < len; i++) {
      if (str[i] != '?' && str[i] != '*') cout << str[i];
    }
  else if (t > l && s > 0) {
    int ex = t - l;
    bool flag = true;
    for (int i = 0; i < len; i++) {
      if (str[i] == '*' && flag) {
        while (ex--) cout << str[i - 1];
        flag = false;
      }
      if (str[i] != '?' && str[i] != '*') cout << str[i];
    }
  } else if (t < l && c + s >= (l - t)) {
    int ex = l - t;
    bool flag = true;
    int idx = 0;
    for (int i = 0; i < len; i++) {
      if (str[i] == '*' || str[i] == '?') {
        if (flag) {
          idx = max(0, idx - 1);
          ex--;
          if (ex == 0) flag = false;
        }
      } else
        str[idx++] = str[i];
    }
    for (int i = 0; i < t; i++)
      if (str[i] != '?' && str[i] != '*') cout << str[i];
  } else
    puts("Impossible");
  return 0;
}
