#include <bits/stdc++.h>
using namespace std;

const int INF = 1000000007;

#define f first
#define s second

int main()
{
    #ifndef LOCAL_DEBUG
    freopen("typing.in", "rt", stdin);
    freopen("typing.out", "wt", stdout);
    #endif
    ios::sync_with_stdio(false);
    int n, m, l;
    cin >> m >> n >> l;
    vector < pair < string, int > > a(n);
    vector < int64_t > res(m + 1, INF);
    int lmax = 0;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].s >> a[i].f;
        if (a[i].f.size() > lmax)
            lmax = a[i].f.size();
    }
    res[0] = 0;
    for (int i = 1; i <= m; i++)
    {
        for (int j = i - 1; j >= 0 && j >= i - lmax; j--)
        {
            for (int x = 0; x < n; x++)
            {
                if (res[j] + a[x].s < res[i])
                {
                    for (int y = 0; y <= a[x].f.size(); y++)
                    {
                        if (s.substr(j, i - j) == a[x].f.substr(0, y) || s.substr(j, i - j) == a[x].f.substr(a[x].f.size() - y))
                        {
                            res[i] = res[j] + a[x].s;
                        }
                    }
                }
            }
        }
        if (res[i] == INF)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << res[m] << endl;
    /*#ifdef LOCAL_DEBUG
    for (int i = 0; i < res.size(); i++)
    {
        cout << res[i] << ' ' << s.substr(0, i) << endl;
    }
    #endif*/
    return 0;
}

