#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k, c = 0, sn = 0, x = 0, flag = 0, count = 0;
  vector<char> v;
  cin >> s;
  cin >> k;
  for (int i = 0; s[i]; i++) {
    if (s[i] == '?') {
      c++;
    } else if (s[i] == '*') {
      sn++;
    } else {
      x++;
    }
  }
  if (k > x) {
    if (sn == 0) {
      cout << "Impossible" << endl;
    } else {
      for (int i = 0; s[i]; i++) {
        if (s[i] == '*') {
          if (flag == 1) {
            continue;
          } else {
            for (int j = 1; j <= k - x; j++) {
              v.push_back(s[i - 1]);
            }
            flag = 1;
          }
        } else if (s[i] == '?') {
          continue;
        } else {
          v.push_back(s[i]);
        }
      }
    }
  } else if (k < x) {
    if (sn + c < x - k) {
      cout << "Impossible" << endl;
    } else {
      for (int i = 0; s[i]; i++) {
        if (s[i] == '?') {
          if (count < x - k) {
            v.pop_back();
            count++;
            continue;
          } else {
            continue;
          }
        }
        if (s[i] == '*') {
          if (count < x - k) {
            v.pop_back();
            count++;
            continue;
          } else {
            continue;
          }
        } else {
          v.push_back(s[i]);
        }
      }
    }
  } else if (x == k) {
    for (int i = 0; s[i]; i++) {
      if (s[i] == '?' || s[i] == '*') {
        continue;
      } else {
        v.push_back(s[i]);
      }
    }
  }
  vector<char>::iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    cout << *it;
  }
  cout << endl;
  return 0;
}
