#include <iostream>
#include <vector>
#include <string>
using namespace std;

bool isMatch(string s, string p) {
    int m = s.length(), n = p.length();
    vector<vector<bool>> dp(m + 1, vector<bool>(n + 1, false));

    // Base case: both strings are empty
    dp[0][0] = true;

    // Initialize dp for patterns with '*' that can match an empty string
    for (int j = 2; j <= n; j++) {
        if (p[j - 1] == '*') {
            dp[0][j] = dp[0][j - 2];
        }
    }

    // Fill the dp table
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (p[j - 1] == '.' || p[j - 1] == s[i - 1]) {
                // Current characters match or pattern has '.'
                dp[i][j] = dp[i - 1][j - 1];
            } else if (p[j - 1] == '*') {
                // Handle '*'
                dp[i][j] = dp[i][j - 2]; 
                // Treat '*' as matching zero of the preceding character
                if (p[j - 2] == '.' || p[j - 2] == s[i - 1]) {
                    dp[i][j] = dp[i][j] || dp[i - 1][j]; 
                    // Match one or more of the preceding character
                }
            }
        }
    }

    return dp[m][n];
}

int main() {
    string s;
    string p;

	cin >> s >> p;

    cout << boolalpha << isMatch(s, p) << endl; 

    return 0;
}