#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int alpha = 0, candy = 0, star = 0;
  int len = str.length();
  for (int i = 0; i < len; i++) {
    if (str[i] >= 'a' && str[i] <= 'z') {
      alpha++;
    } else if (str[i] == '?') {
      candy++;
    } else {
      star++;
    }
  }
  int k;
  cin >> k;
  if (alpha == k) {
    string ans = "";
    for (int i = 0; i < len; i++) {
      if (str[i] >= 'a' && str[i] <= 'z') {
        ans += str[i];
      }
    }
    cout << ans << endl;
  } else if (alpha < k) {
    if (star == 0) {
      cout << "Impossible\n";
    } else {
      int loc = 0;
      for (int i = 0; i < len; i++) {
        if (str[i] == '*') {
          loc = i;
          break;
        }
      }
      string ans = "";
      for (int i = 0; i < loc; i++) {
        if (str[i] >= 'a' && str[i] <= 'z') {
          ans += str[i];
        }
      }
      for (int i = 1; i <= (k - alpha); i++) {
        ans += str[loc - 1];
      }
      for (int i = loc; i < len; i++) {
        if (str[i] >= 'a' && str[i] <= 'z') {
          ans += str[i];
        }
      }
      cout << ans << endl;
    }
  } else {
    if (candy + star == 0) {
      cout << "Impossible\n";
    } else {
      if (alpha - (candy + star) == k) {
        str += '.';
        string ans = "";
        for (int i = 0; i < len; i++) {
          if (str[i + 1] == '?' || str[i + 1] == '*') {
            i += 1;
          } else if (str[i] >= 'a' && str[i] <= 'z') {
            ans += str[i];
          }
        }
        cout << ans << endl;
      } else if (k > alpha - (candy + star)) {
        int rem = alpha - k;
        string ans = "";
        str += '.';
        for (int i = 0; i < len; i++) {
          if (rem > 0 && (str[i + 1] == '?' || str[i + 1] == '*')) {
            rem--;
            i++;
          } else if (str[i] >= 'a' && str[i] <= 'z') {
            ans += str[i];
          }
        }
        cout << ans << endl;
      } else if (k < alpha - (candy + star)) {
        cout << "Impossible\n";
      }
    }
  }
  return 0;
}
