#include <bits/stdc++.h>
using namespace std;
const double PI = atan(1.0) * 4;
const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, -1, 0, 1};
const long long INF = (long long)2e18 + 50;
const int maximum = numeric_limits<int>::max();
const int minimum = numeric_limits<int>::min();
const int N = 1e9;
const int mod = 1e9 + 7;
long long power(long long a, long long e) {
  long long res = 1LL;
  while (e > 0) {
    if (e % 2 == 1) res = res * a;
    a = a * a;
    e /= 2;
  }
  return res;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  T = 1;
  while (T--) {
    string s;
    cin >> s;
    int n = s.length();
    int k;
    cin >> k;
    if (k == n) {
      bool ok = false;
      for (int i = 0; i < n; i++) {
        if (s[i] == '*') {
          ok = true;
          break;
        }
      }
      if (ok) {
        int extra = 0;
        for (int i = 0; i < n; i++) {
          if (s[i] == '?' || s[i] == '*') {
            extra++;
          }
        }
        vector<char> ans;
        bool ok1 = false;
        for (int i = 0; i < n; i++) {
          if (s[i] != '?' && s[i] != '*') {
            ans.push_back(s[i]);
          }
          if (s[i] == '?') continue;
          if (s[i] == '*' && !ok1) {
            int tmp = extra;
            while (tmp--) {
              ans.push_back(s[i - 1]);
            }
            ok1 = true;
          }
          if (s[i] == '*' && ok1) continue;
        }
        for (int i = 0; i < (int)ans.size(); i++) {
          cout << ans[i];
        }
        cout << "\n";
      } else {
        bool ok1 = true;
        for (int i = 0; i < n; i++) {
          if (s[i] == '?') {
            ok1 = false;
          }
        }
        if (!ok1) {
          cout << "Impossible\n";
        } else {
          cout << s << "\n";
        }
      }
    } else if (k > n) {
      bool ok = false;
      for (int i = 0; i < n; i++) {
        if (s[i] == '*') {
          ok = true;
          break;
        }
      }
      if (!ok) {
        cout << "Impossible\n";
      } else {
        int extra = 0;
        for (int i = 0; i < n; i++) {
          if (s[i] == '?' || s[i] == '*') {
            extra++;
          }
        }
        vector<char> ans;
        bool ok1 = false;
        for (int i = 0; i < n; i++) {
          if (s[i] != '?' && s[i] != '*') {
            ans.push_back(s[i]);
          }
          if (s[i] == '?') continue;
          if (s[i] == '*' && !ok1) {
            int tmp = k - n + extra;
            while (tmp--) {
              ans.push_back(s[i - 1]);
            }
            ok1 = true;
          }
          if (s[i] == '*' && ok1) continue;
        }
        for (int i = 0; i < (int)ans.size(); i++) {
          cout << ans[i];
        }
        cout << "\n";
      }
    } else {
      bool ok = false;
      for (int i = 0; i < n; i++) {
        if (s[i] == '?' || s[i] == '*') {
          ok = true;
          break;
        }
      }
      if (!ok) {
        cout << "Impossible\n";
      } else {
        int extra = 0;
        int extra1 = 0;
        for (int i = 0; i < n; i++) {
          if (s[i] == '?') {
            extra++;
            extra1++;
          }
          if (s[i] == '*') {
            extra++;
            extra1++;
          }
        }
        if (n - extra - extra1 > k) {
          cout << "Impossible\n";
        } else {
          int net = n - extra - k;
          if (net >= 0) {
            vector<char> ans;
            for (int i = 0; i < n - 1; i++) {
              if (s[i] != '?' && s[i] != '*' && s[i + 1] != '?' &&
                  s[i + 1] != '*') {
                ans.push_back(s[i]);
              } else if (s[i] != '?' && s[i] != '*' &&
                         (s[i + 1] == '?' || s[i + 1] == '*') && net) {
                net--;
              } else if (s[i] != '?' && s[i] != '*' &&
                         (s[i + 1] == '?' || s[i + 1] == '*') && !net) {
                ans.push_back(s[i]);
              }
            }
            if (s[n - 1] != '?' && s[n - 1] != '*') ans.push_back(s[n - 1]);
            for (int i = 0; i < (int)ans.size(); i++) {
              cout << ans[i];
            }
            cout << "\n";
          } else {
            vector<char> ans;
            bool ok1 = false;
            for (int i = 0; i < n; i++) {
              if (s[i] != '?' && s[i] != '*') {
                ans.push_back(s[i]);
              }
              if (s[i] == '?') continue;
              if (s[i] == '*' && !ok1) {
                int tmp = k - (n - extra);
                while (tmp--) {
                  ans.push_back(s[i - 1]);
                }
                ok1 = true;
              }
              if (s[i] == '*' && ok1) continue;
            }
            if (ans.size() != k) {
              cout << "Impossible\n";
            } else {
              for (int i = 0; i < (int)ans.size(); i++) {
                cout << ans[i];
              }
              cout << "\n";
            }
          }
        }
      }
    }
  }
  return 0;
}
