#include <bits/stdc++.h>
using namespace std;
int k;
char s[1000000];
vector<char> ANS;
int main() {
  scanf("%s", s);
  scanf("%d", &k);
  int star = 0;
  int cane = 0;
  int S = strlen(s);
  int starind = -1;
  for (int i = 0; i < S; i++) {
    if (s[i] == '*') {
      star++;
      starind = i;
    } else if (s[i] == '?')
      cane++;
  }
  if (star) {
    if (S - cane - star - cane - star > k)
      printf("Impossible");
    else {
      int loop = k - S + 2 * (star + cane);
      for (int i = S - 1; i >= 0; i--) {
        if (i == starind) {
          for (int qq = 0; qq < loop; qq++) ANS.push_back(s[i - 1]);
          i--;
        } else if (s[i] == '?' || s[i] == '*') {
          i--;
        } else {
          ANS.push_back(s[i]);
        }
      }
    }
  } else {
    if (S - 2 * cane > k || k > S - cane)
      printf("Impossible");
    else {
      int live = k - S + 2 * cane;
      int nowlived = 0;
      for (int i = S - 1; i >= 0; i--) {
        if (s[i] == '?') {
          if (nowlived >= live)
            i--;
          else
            nowlived++;
        } else
          ANS.push_back(s[i]);
      }
    }
  }
  for (int i = ANS.size() - 1; i >= 0; i--) printf("%c", ANS[i]);
}
