import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String p = sc.next();
            String s = sc.next();

            System.out.println(isMatch(s,p));
        }
        sc.close();
    }
     public static  boolean isMatch(String s, String p) {

        if(s.length() == 0 && p.length() == 0)return true;
        if(s.length()!= 0 && p.length() == 0) return false;
        boolean [][] dp = new boolean [s.length()+1][p.length()+1];
        dp[0][0] = true;
        for(int j = 2; j <= p.length(); j++){
            if(p.charAt(j-1) == '*' && dp[0][j-2]){
                dp[0][j] = true;
            }
        }
        for(int i = 1; i <= s.length(); i++){
            for(int j = 1; j <= p.length(); j++){
                char a = s.charAt(i-1), b = p.charAt(j-1);
                if(a == b || b == '?'){
                    dp[i][j] = dp[i-1][j-1];
                }
                else if(b == '*'){
                    if(j>=2){
                         dp[i][j] = dp[i-1][j] || dp[i][j-2];
                    }

                       }

                else dp[i][j] = false;
            }
        }
        return dp[s.length()][p.length()];
    }
}