#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long ncp(long long n, long long p) {
  if (p == 0) {
    return 1;
  }
  long long ans = 1ll;
  for (long long i = n; i > n - p; i--) {
    ans *= i;
  }
  for (long long i = 1; i <= p; i++) {
    ans /= i;
  }
  return ans;
}
string dectoBinary(long long n) {
  string r;
  while (n != 0) {
    r = (n % 2 == 0 ? "0" : "1") + r;
    n /= 2;
  }
  return r;
}
long long binaryToDecimal(string n) {
  string num = n;
  long long dec_value = 0;
  long long base = 1;
  long long len = num.length();
  for (long long i = len - 1; i >= 0; i--) {
    if (num[i] == '1') {
      dec_value += base;
      dec_value %= 1000003;
    }
    base = (base * 2) % 1000003;
  }
  return dec_value;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  string s;
  cin >> s;
  long long size1 = 0, size2 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '*')
      size2++;
    else if (s[i] == '?')
      size1++;
  }
  long long k;
  cin >> k;
  if ((s.size() - 2 * (size1 + size2)) > k ||
      (size2 == 0 && (s.size() - size1) < k))
    cout << "Impossible";
  else {
    long long size = s.size() - size1 - size2;
    if (size > k) {
      long long x = size - k;
      for (int i = 0; i < s.size(); i++) {
        if (x > 0 && (s[i + 1] == '?' || s[i + 1] == '*'))
          x--;
        else if ((s[i] != '?' && s[i] != '*'))
          cout << s[i];
      }
    } else if (size < k) {
      long long d = k - size;
      for (int i = 0; i < s.size(); i++) {
        if ((d > 0) && (i > 0) && (s[i] == '*')) {
          while (d > 0) {
            cout << s[i - 1];
            d--;
          }
        } else if ((s[i] != '?' && s[i] != '*'))
          cout << s[i];
      }
    } else {
      for (int i = 0; i < s.size(); i++) {
        if ((s[i] != '?' && s[i] != '*')) cout << s[i];
      }
    }
  }
  return 0;
}
