#include <bits/stdc++.h>

using namespace std;

struct Node
{
    int next[2];
    long long currC;

    Node()
    {
        next[0] = next[1] = -1;
        currC = -1;
    }
};

const int maxMemSize = 1e7;
int currMemSize = 1;

Node memory[maxMemSize];

buildNext(int ind, int p, long long cost)
{
    if (memory[ind].next[p] == -1)
        memory[ind].next[p] = currMemSize++;

    int ans = memory[ind].next[p];

    if (cost != -1)
    {
        if (memory[ans].currC == -1)
            memory[ans].currC = cost;
        else
            memory[ans].currC = min(memory[ans].currC, cost);
    }

    return ans;
}

int main()
{
    freopen("typing.in", "r", stdin);
    freopen("typing.out", "w", stdout);

    int m, n, L;
    cin >> m >> n >> L;

    string SS;
    cin >> SS;

    vector<long long> ans(m + 1, -1);
    ans[m] = 0;

    long long cost;
    string s;
    int ind;

    while (--n >= 0)
    {
        cin >> cost >> s;

        ind = 0;

        for (auto it = s.begin(); it != s.end(); it++)
            ind = buildNext(ind, *it - '0', cost);

        for (int i = 1; i < (int)s.size(); i++)
        {
            ind = 0;

            for (int j = i; j < (int)s.size(); j++)
                ind = buildNext(ind, s[j] - '0', (j != (int)s.size() - 1 ? -1 : cost));
        }
    }

    for (int i = m - 1; i >= 0; i--)
    {
        ind = memory[0].next[SS[i] - '0'];

        for (int h = 1; i + h <= m && ind != -1; h++)
        {
            if (ans[i + h] != -1 && memory[ind].currC != -1)
            {
                if (ans[i] == -1)
                    ans[i] = (memory[ind].currC + ans[i + h]);
                else
                    ans[i] = min(ans[i], memory[ind].currC + ans[i + h]);
            }

            ind = memory[ind].next[SS[i + h] - '0'];
        }
    }

    cout << ans[0];

    return 0;
}
