#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int M = 55;
const int inf = 1e9;
string alpha;
struct aho_corasick {
  vector<map<char, int>> trie;
  vector<int> cnt;
  vector<int> link;
  int new_node() {
    trie.push_back(map<char, int>());
    cnt.push_back(0);
    link.push_back(0);
    return (int)(trie).size() - 1;
  }
  aho_corasick() { new_node(); }
  void insert(string &s, int add, int x = 0) {
    for (int i = (0); i <= (((int)(s).size()) - 1); i += (+1)) {
      if (!trie[x].count(s[i])) {
        trie[x][s[i]] = new_node();
      }
      x = trie[x][s[i]];
    }
    cnt[x] += add;
  }
  int suffix(int x, char c) {
    while (x && !trie[x][c]) {
      x = link[x];
    }
    return trie[x][c];
  }
  void build_links() {
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (char c : alpha) {
        int &y = trie[x][c];
        if (y == 0) {
          y = trie[link[x]][c];
          continue;
        }
        link[y] = x ? suffix(link[x], c) : 0;
        cnt[y] += cnt[link[y]];
        q.push(y);
      }
    }
  }
};
aho_corasick aho;
int dp[N][2 * M];
string code, s, t;
template <typename T>
void umax(T &a, T b) {
  a = max(a, b);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
  for (int c = ('a'); c <= ('z'); c += (+1)) {
    alpha.push_back(char(c));
  }
  cin >> code >> s >> t;
  aho.insert(s, +1);
  aho.insert(t, -1);
  aho.build_links();
  for (int i = (0); i <= (((int)(code).size() + 1) - 1); i += (+1)) {
    for (int x = (0); x <= (((int)(aho.trie).size() + 1) - 1); x += (+1)) {
      dp[i][x] = -inf;
    }
  }
  dp[0][0] = 0;
  for (int i = (0); i <= (((int)(code).size()) - 1); i += (+1)) {
    for (int x = (0); x <= (((int)(aho.trie).size()) - 1); x += (+1)) {
      if (code[i] == '*') {
        for (char c : alpha) {
          int y = aho.trie[x][c];
          umax(dp[i + 1][y], dp[i][x] + aho.cnt[y]);
        }
      } else {
        int y = aho.trie[x][code[i]];
        umax(dp[i + 1][y], dp[i][x] + aho.cnt[y]);
      }
    }
  }
  int ans = -inf;
  for (int x = (0); x <= (((int)(aho.trie).size()) - 1); x += (+1)) {
    umax(ans, dp[(int)(code).size()][x]);
  }
  if (ans == -inf) {
    ans = -1;
  }
  cout << ans << '\n';
  return 0;
}
