#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-Ofast")
using namespace std;
void rearrange(long long arr[], long long n) {
  long long temp[n];
  long long small = 0, large = n - 1;
  long long flag = true;
  for (long long i = 0; i < n; i++) {
    if (flag)
      temp[i] = arr[large--];
    else
      temp[i] = arr[small++];
    flag = !flag;
  }
  for (long long i = 0; i < n; i++) arr[i] = temp[i];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string a;
  cin >> a;
  long long k, i;
  cin >> k;
  long long snow = 0, candy = 0;
  for (i = 0; i < a.size(); i++) {
    if (a[i] == '*')
      snow++;
    else if (a[i] == '?')
      candy++;
  }
  long long cha = k - (a.size() - snow - candy);
  if (cha > 0) {
    if (snow == 0)
      cout << "Impossible";
    else {
      string ans = "";
      for (i = a.size() - 1; i >= 0; i--) {
        if (a[i] == '?') continue;
        if (a[i] == '*') {
          while (cha > 0) {
            ans = ans + a[i - 1];
            cha--;
          }
        } else {
          ans = ans + a[i];
        }
      }
      reverse(ans.begin(), ans.end());
      cout << ans;
    }
  } else {
    if (a.size() - 2 * snow - 2 * candy > k)
      cout << "Impossible";
    else {
      vector<char> v(a.size(), '1');
      for (i = a.size() - 1; i >= 0; i--) {
        if (a[i] == '?' || a[i] == '*') {
          i--;
        } else {
          v[i] = a[i];
          k--;
        }
      }
      for (i = a.size() - 1; i >= 0; i--) {
        if (k > 0 && (a[i] == '?' || a[i] == '*')) {
          k--;
          v[i] = a[i - 1];
        }
      }
      for (i = 0; i < a.size(); i++) {
        if (v[i] != '1') cout << v[i];
      }
    }
  }
}
