#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main()
{
map<string, bool> mapa;
string s;
cin >> s;
int n;
cin >> n;
vector<string> words;
for(int i = 0; i < n; i++) {
string x;
cin >> x;
words.push_back(x);
mapa[x] = true;
}
if(mapa[s] == false) {
cout << s << endl;
}
else {
for(int i = 1; i <= n + 1; i++) {
string tmp = s + to_string(i);
if(mapa[tmp] == false) {
cout << tmp << endl;
break;
}
}
}
return 0;
}