#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
set<long long int> st1;
set<long long int> st2;
set<string> st3;
vector<long long int> v1;
vector<long long int> v2;
vector<long long int> v3;
vector<long long int> v4;
vector<long long int> v5;
vector<pair<long long int, long long int> > v6;
vector<pair<long long int, long long int> > v16;
vector<string> v7;
vector<string> v8;
vector<char> v9;
vector<char> v99;
set<char> s11;
set<char> s22;
vector<double> v11;
list<long long int> l;
unordered_map<long long int, long long int> mp;
unordered_multiset<string> sm;
stack<long long int> stk2;
stack<long long int> stk1;
vector<vector<pair<long long int, long long int> > > adjlist(100000);
set<string> dsu;
unordered_map<long long int, long long int> mp1;
vector<pair<long long int, long long int> > node;
vector<vector<long long int> > vc(101);
int main() {
  string s;
  cin >> s;
  long long int n;
  cin >> n;
  long long int c1 = 0, c2 = 0, total = 0;
  stack<char> stk;
  for (long long int i = 0; i < s.length(); i++) {
    if (s[i] != '?' && s[i] != '*') {
      total++;
    }
    if (s[i] == '?') c1++;
    if (s[i] == '*') c2++;
  }
  long long int lowerpart = total - (c1 + c2);
  long long int higherpart = total;
  if (n < lowerpart) cout << "Impossible" << endl;
  if (n > higherpart) {
    if (c2 == 0)
      cout << "Impossible" << endl;
    else {
      long long int c = 0;
      long long int remain = (n - higherpart);
      for (long long int i = 0; i < s.length(); i++) {
        if (s[i] != '?' && s[i] != '*') {
          stk.push(s[i]);
        }
        if (s[i] == '?') continue;
        if (s[i] == '*') {
          if (c == 0) {
            for (long long int i = 0; i < remain; i++) {
              stk.push(stk.top());
            }
            c = 1;
          } else
            continue;
        }
      }
    }
  }
  if (n >= lowerpart && n <= higherpart) {
    long long int remove2 = higherpart - n;
    long long int c1 = 0;
    for (long long int i = 0; i < s.length(); i++) {
      if (s[i] == '?' || s[i] == '*') {
        if (c1 < remove2) {
          stk.pop();
          c1++;
        } else
          continue;
      } else {
        stk.push(s[i]);
      }
    }
  }
  while (!stk.empty()) {
    v9.push_back(stk.top());
    stk.pop();
  }
  reverse(v9.begin(), v9.end());
  for (long long int i = 0; i < v9.size(); i++) {
    cout << v9[i];
  }
  cout << endl;
  return 0;
}
