#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string c;
    cin >> c;
    long long n;
    cin >> n;
    string bad[n];
    for(int i = 0; i < n; i++)
    {
        cin >> bad[i];
    }
    while(true)
    {
        long long l = inf;
        long long ind = -1;
        for(int i = 0; i < n; i++)
        {
            int p;
            if((p = c.find(bad[i])) != string::npos)
            {
                if(p < l) {
                    l = p;
                    ind = i;
                }
            }

        }
        if(ind == -1) break;
        c.erase(l, bad[ind].size());
    }
    cout << c;



    return 0;
}
