#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  long long i, k;
  cin >> k;
  long long n = s.size();
  long long c1 = 0, c2 = 0;
  for (i = 0; i < n; i++) {
    if (s[i] == '?')
      c1++;
    else if (s[i] == '*')
      c2++;
  }
  long long minl = n - 2 * (c1 + c2);
  if (k < minl) {
    cout << "Impossible" << endl;
    return 0;
  }
  long long maxl = n - (c1 + c2);
  if (k > maxl && c2 == 0) {
    cout << "Impossible" << endl;
    return 0;
  }
  long long count = k - minl;
  for (i = 0; i < n; i++) {
    if (s[i] == '?' || s[i] == '*') continue;
    if (s[i + 1] != '?' && s[i + 1] != '*')
      cout << s[i];
    else if (s[i + 1] == '?') {
      if (count > 0) {
        cout << s[i];
        count--;
      }
    } else if (s[i + 1] == '*') {
      while (count > 0) {
        cout << s[i];
        count--;
      }
    }
  }
  cout << endl;
  return 0;
}
