#include <bits/stdc++.h>

#define fi "ASTRING.INP"
#define fo "ASTRING.OUT"

#define ll long long

using namespace std;

int n, m;
string a, b;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    cin >> n >> m;
    cin >> a;
    cin >> b;

    int j = 0;
    for (int i = 0; i < n; i++) {
        while (a[i] != b[j] && j < m) j++;
        if (a[i] != b[j]) {
            cout << "N";
            return 0;
        }
        else j++;
    }
    cout << "Y";
    return 0;
}