#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> word_list;
void sort_word_list(string end_alpha)
{
for (int i = 0; i < word_list.size() - 1; i++)
{
for (int j = i + 1; j < word_list.size(); j++)
{
if (word_list[i].find(end_alpha) == 0)
{
if (word_list[j].find(end_alpha) == 0)
{
if (word_list[i].length() == word_list[j].length())
{
if (word_list[i] > word_list[j])
{
swap(word_list[i], word_list[j]);
}
}
else if (word_list[i].length() < word_list[j].length())
{
swap(word_list[i], word_list[j]);
}
}
}
else
{
if (word_list[j].find(end_alpha) == 0)
{
swap(word_list[i], word_list[j]);
}
}
}
}
}
int main()
{
int index, num;
cin >> index >> num;
cin.ignore();
for (int i = 0; i < num; i++)
{
string word;
getline(cin, word);
word_list.push_back(word);
}
string ans = word_list[index];
string end_alpha = ans.substr(ans.length() - 1, 1);
word_list.erase(word_list.begin() + index);
sort_word_list(end_alpha);
while (true)
{
if (word_list.size() == 0)
{
break;
}
if (word_list[0].find(end_alpha) != 0)
{
break;
}
ans += word_list[0];
word_list.erase(word_list.begin());
end_alpha = ans.substr(ans.length() - 1, 1);
sort_word_list(end_alpha);
}
cout << ans << endl;
return 0;
}