#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

struct bor{
    long long c;
    bor* u[2];
    bool is[2];
    bor(long long _c){
        is[0] = 0;
        is[1] = 0;
        c = _c;
    }
    void add(string &s, int l, int r, long long cc){
        c = min(c, cc);
        if (l >= r){
            return;
        }
        int cha = s[l]-'0';
        if (is[cha]){
            (*u[cha]).add(s, l+1, r, cc);
        }
        else{
            is[cha] = 1;
            u[cha] = new bor(cc);
            (*u[cha]).add(s, l+1, r, cc);
        }
    }
};

struct ukas{
    bor* b;
    ukas(bor* _b){
        b = _b;
    }
    void remade(bor* _b){
        b = _b;
    }
    bool next(int x){
        if (!(b->is[x])){
            return 0;
        }
        else{
            b = b->u[x];
            return 1;
        }
    }
    long long get(){
        return b->c;
    }
};

int main(){
    ifstream cin("typing.in");
    ofstream cout("typing.out");

    int n,m,L;
    long long INF = 1000000000000000000;
    //scanf("%d %d %d", &n, &m, &L);
    cin>>m>>n>>L;

    string s;
    cin>>s;
    string sr;
    sr.resize(s.size());
    for (int i = 0; i < s.size(); i++){
        sr[m-1-i] = s[i];
    }

    bor suf(0);
    bor pref(0);

    for (int i = 0; i < n; i++){
        string s1;
        long long ctoim;
        string s1r;
        cin>>ctoim>>s1;
        for (int i = 0; i < s1.size(); i++){
            s1r[s1.size()-1-i] = s1[i];
        }
        pref.add(s1, 0, s1.size(), ctoim);
        suf.add(s1r, 0, s1.size(), ctoim);
    }

    vector<long long> dyn(m, INF);

    for (int i = 0; i < m; i++){
        ukas usuf(&suf);
        for (int j = i; j >= 0; j--){
            if (usuf.next(s[j]-'0')){
                if (j == 0){
                    dyn[i] = min(dyn[i], usuf.get());
                }
                else{
                    dyn[i] = min(dyn[i], usuf.get() + dyn[j-1]);
                }
            }
            else{
                break;
            }
        }

        ukas upref  (&pref);

        for (int j = i+1; j < m; j++){
            if (upref.next(s[j]-'0')){
                //cout<<j;
                dyn[j] = min(dyn[j], dyn[i]+upref.get());
            }
            else{
                break;
            }
        }
        //cout<<dyn[i]<<" ";
    }
    if (dyn[m-1] == INF){
        cout<<-1;
        return 0;
    }
    cout<<dyn[m-1];
}


/*
ukas usuf(&suf);
        for (int ir = m-i-1; ir < m; ir++){
            if (usuf.next(sr[ir] - '0')){
                if (ir == m-1){
                    dyn[i] = min(dyn[i], usuf.get());
                }
                else{
                    dyn[i] = min(dyn[i], usuf.get() + dyn[m-(ir+1)-1]);
                }
            }
            else{
                break;
            }
        }
        */
