#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int len = 0, cntSnow = 0, cntCandy = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] != '?' && str[i] != '*')
      len++;
    else if (str[i] == '?')
      cntCandy++;
    else if (str[i] == '*')
      cntSnow++;
  }
  int k;
  cin >> k;
  string ans = "";
  str += '#';
  if (len > k) {
    len -= cntCandy;
    if (len == k) {
      for (int i = 0; i < str.length() - 1; i++) {
        if (str[i] == '?' || str[i] == '*')
          continue;
        else if (str[i + 1] != '?')
          ans += str[i];
      }
    } else if (len < k) {
      bool f = 0;
      for (int i = 0; i < str.length() - 1; i++) {
        if (str[i] == '?' || str[i] == '*')
          continue;
        else if (str[i + 1] == '?' && !f) {
          ans += str[i];
          len++;
          if (len == k) f = 1;
        } else if (str[i + 1] != '?')
          ans += str[i];
      }
    } else if (len > k) {
      len -= cntSnow;
      if (len == k) {
        for (int i = 0; i < str.length() - 1; i++) {
          if (str[i] == '?' || str[i] == '*')
            continue;
          else if (str[i + 1] != '?' && str[i + 1] != '*')
            ans += str[i];
        }
      } else if (len < k) {
        bool f = 0;
        for (int i = 0; i < str.length() - 1; i++) {
          if (str[i] == '?' || str[i] == '*')
            continue;
          else if (str[i + 1] == '*' && !f) {
            while (len < k) {
              ans += str[i];
              len++;
            }
            f = 1;
          } else if (str[i + 1] != '?' && str[i + 1] != '*')
            ans += str[i];
        }
      } else {
        cout << "Impossible\n";
        return 0;
      }
    }
  } else if (len < k) {
    if (cntSnow) {
      len -= cntSnow;
      bool f = 0;
      for (int i = 0; i < str.length() - 1; i++) {
        if (str[i] == '?' || str[i] == '*')
          continue;
        else if (str[i + 1] == '*' && !f) {
          while (len < k) {
            ans += str[i];
            len++;
          }
          f = 1;
        } else if (str[i + 1] != '*')
          ans += str[i];
      }
    } else {
      cout << "Impossible\n";
      return 0;
    }
  } else if (len == k) {
    for (int i = 0; i < str.length() - 1; i++) {
      if (str[i] == '?' || str[i] == '*')
        continue;
      else
        ans += str[i];
    }
  }
  cout << ans << endl;
  return 0;
}
