#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const int MAXN = 1e6;
long long t[MAXN], as[MAXN];


void push(int v, int vl, int vr)
{
    if (vl + 1 != vr)
    {
        t[2 * v] = min(as[v], t[2 * v]);
        t[2 * v + 1] = min(as[v], t[2 * v + 1]);
        as[2 * v] = min(as[2 * v], as[v]);
        as[2 * v + 1] = min(as[2 * v+ 1], as[v]);
    }
    as[v] = INF;
}

long long get(int v, int vl, int vr, int ql, int qr)
{
    push(v, vl, vr);
    if (qr <= vl || vr <= ql)
        return INF;
    else if (ql <= vl && vr <= qr)
        return t[v];
    else
    {
        int vm = (vl + vr) / 2;
        return min(get(2 * v, vl, vm, ql, qr), get(2 * v + 1, vm, vr, ql, qr));
    }
}

void ass(int v, int vl, int vr, int ql, int qr, long long x)
{
    push(v, vl, vr);
    if (qr <= vl || vr <= ql)
        return;
    else if (ql <= vl && vr <= qr)
        t[v] = min(t[v], x), as[v] = x;
    else
    {
        int vm = (vl + vr) / 2;
        ass(2 * v, vl, vm, ql, qr, x);
        ass(2 * v + 1, vm, vr, ql, qr, x);
        t[v] = min(t[2 * v], t[2 * v + 1]);
    }
}


struct node
{
    node *l;
    node *r;
    int cost;
};

node * create_node(int k)
{
    node * t = new node();
    t->cost = k;
    return t;
}

string t;

void add(int i, int c, node *p)
{
    p->cost = min(p->cost, c);
    if (i == t.size())
        return;
    if (t[i] == '0')
    {
        if (p->l == 0)
            p->l = create_node(c);
        add(i + 1, c, p->l);
    }
    else
    {
        if (p->r == 0)
            p->r = create_node(c);
        add(i + 1, c, p->r);
    }
}


int main()
{
    freopen("typing.in", "r", stdin);
    freopen("typing.out", "w", stdout);
    int m, n, l;
    cin >> m >> n >> l;
    if (n > 200)
    {
        string s;
        cin >> s;
        node *pref = create_node(0);
        node *suff = create_node(0);
        for (int i = 0; i < n; ++i)
        {
            int c;
            cin  >> c >> t;
            add(0, c, pref);
            reverse(t.begin(), t.end());
            add(0, c, suff);
        }

        vector <long long> dp(m + 1, INF);
        dp[0] = 0;
        for (int i = 0; i <= m; ++i)
        {
            int j = i;
            node *now = suff;
            while (j > 0)
            {
                if (s[j - 1] == '0' && now->l)
                    j--, now = now->l, dp[i] = min(dp[j] + now->cost, dp[i]);
                else if (s[j - 1] == '1' && now->r)
                    j--, now = now->r, dp[i] = min(dp[j] + now->cost, dp[i]);
                else
                    break;
            }
            j = i;
            now = pref;
            while (j < m)
            {
                if (s[j] == '0' && now->l)
                    j++, now = now->l, dp[j] = min(dp[i] + now->cost, dp[j]);
                else if (s[j] == '1' && now->r)
                    j++, now = now->r, dp[j] = min(dp[i] + now->cost, dp[j]);
                else
                    break;
            }
        }
        if (dp[m] == INF)
            cout << -1 << endl;
        else
            cout << dp[m] << endl;
        return 0;
    }
    string s;
    cin >> s;
    string srev = s;
    reverse(srev.begin(), srev.end());
    vector <int> c(n);
    for (int i = 0; i < MAXN; ++i)
        t[i] = as[i] = INF;
    vector <vector <int> > mp(n, vector <int> (m)), ms(n, vector <int> (m));
    for (int i = 0; i < n; ++i)
    {
        string t;
        cin >> c[i] >> t;
        string zs = t + '&' + s;
        vector <int> z(zs.size(), 0);
        z[0] = zs.size();
        int l = 0, r = 0;
        for (int j = 1; j < zs.size(); ++j)
        {
            if (j <= r)
                z[j] =  min(z[j - l], r - j);
            while (j + z[j] < zs.size() && zs[j + z[j]] == zs[z[j]])
                z[j]++;
            if (j + z[j] > r)
            {
                l = j;
                r = j + z[j];
            }
        }
        for (int j = 0; j < m; ++j)
            mp[i][j] = z[j + t.size() + 1];
        reverse(t.begin(), t.end());
        zs = t + '&' + srev;
        z.assign(zs.size(), 0);
        z[0] = zs.size();
        l = 0;
        r = 0;
        for (int j = 1; j < zs.size(); ++j)
        {
            if (j <= r)
                z[j] =  min(z[j - l], r - j);
            while (j + z[j] < zs.size() && zs[j + z[j]] == zs[z[j]])
                z[j]++;
            if (j + z[j] > r)
            {
                l = j;
                r = j + z[j];
            }
        }
        for (int j = 0; j < m; ++j)
            ms[i][j] = z[(int)zs.size() - j - 1];
    }


    ass(1, 0, m + 1, 0, 1, 0);

    for (int i = 0; i <= m; ++i)
    {
        for (int j = 0; j < n && i != 0; ++j)
        {
            long long mn = get(1, 0, m + 1, i - ms[j][i - 1], i);
            ass(1, 0, m + 1, i, i + 1, mn + c[j]);
        }
        long long gt = get(1, 0, m + 1, i, i + 1);
        for (int j = 0; j < n; ++j)
        {
            ass(1, 0, m + 1, i + 1, i + mp[j][i] + 1, gt + c[j]);
        }
    }
    long long ans =  get(1, 0, m + 1, m, m + 1);
    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;
}
