#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  string s;
  int a, n, d = 0, b = 0, c = 0, re;
  cin >> s;
  cin >> a;
  n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == '*') {
      d = 1;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == '?') {
      b++;
    }
    if (s[i] == '*') {
      c++;
    }
  }
  if (d) {
    if (a < n - 2 * b - 2 * c) {
      cout << "Impossible";
    } else {
      for (int i = 0; i < n; i++) {
        if (s[i] - 'a' < 26 && s[i] - 'a' >= 0) {
          if (i + 1 < n) {
            if (s[i + 1] == '*') {
              if (d) {
                for (int j = 0; j < -(n - a - 2 * b - 2 * c); j++) {
                  cout << s[i];
                }
                d = 0;
              }
            } else if (s[i + 1] == '?') {
            } else {
              cout << s[i];
            }
          } else {
            cout << s[i];
          }
        }
      }
    }
  } else {
    re = a - (n - 2 * b - 2 * c);
    if (a < n - 2 * b - 2 * c || a > n - b - c) {
      cout << "Impossible";
    } else {
      for (int i = 0; i < n; i++) {
        if (s[i] - 'a' < 26 && s[i] - 'a' >= 0) {
          if (i + 1 < n) {
            if (s[i + 1] == '?') {
              if (re > 0) {
                cout << s[i];
                re--;
              }
            } else {
              cout << s[i];
            }
          } else {
            cout << s[i];
          }
        }
      }
    }
  }
}
