#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;


int main(int argc, char* argv[]) {
    registerValidation(argc, argv);

    int n = inf.readInt(1, 5000, "n");
    inf.readSpace();
    int m = inf.readInt(1, 10, "m");
    inf.readEoln();

    string wordPattern = "[a-z]{" + to_string(m) + "}";
    string start = inf.readToken(wordPattern, "palavraInicial");
    inf.readSpace();
    string end = inf.readToken(wordPattern, "palavraFinal");
    inf.readEoln();

    unordered_set<string> seen;
    for (int i = 0; i < n; i++) {
        string s = inf.readToken(wordPattern);
        ensuref(seen.count(s) == 0, "As palavras do dicionario do CFG devem ser unicas");
        seen.insert(s);
        inf.readEoln();
    }
    inf.readEof();

    return 0;
}