#include<bits/stdc++.h>

using namespace std;

typedef long long lint;

#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define Df(i, l, r) for(auto i = l; i != r; i--)
#define rs resize
#define asg assign
#define mk make_pair
#define ins insert
#define era erase
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break

const string fname = "typing";

const lint inf = 1e18;

int n, m, L;
string s;
vector<string> t, fs, fp, rt;
vector<int> c;
vector<lint> dp;
string rs;
vector<vector<int> > zs, zp;

#define node stnode

struct node{
    node * l, * r;
    lint val;
};

node * root;

node * build(int l, int r){
    node * nnode = new node;
    if(l == r){
        nnode->val = dp[l];
        ret nnode;
    }
    int mid = (l + r) >> 1;
    nnode->l = build(l, mid);
    nnode->r = build(mid + 1, r);
    nnode->val = min(nnode->l->val, nnode->r->val);
    ret nnode;
}

void upd(node * v, int l, int r, int pos, lint nv){
    if(l == r){
        v->val = min(v->val, nv);
        ret;
    }
    int mid = (l + r) >> 1;
    if(pos <= mid)
        upd(v->l, l, mid, pos, nv);
    else
        upd(v->r, mid + 1, r, pos, nv);
    v->val = min(v->l->val, v->r->val);
}

lint get(node * v, int l, int r, int ul, int ur){
    if(ul > ur)
        ret inf;
    if(l == ur && r == ur)
        ret v->val;
    int mid = (l + r) >> 1;
    ret min(get(v->l, l, mid, ul, min(ur, mid)), get(v->r, mid + 1, r, max(ul, mid + 1), ur));
}

#undef node

struct node{
    vector<node*> nxt;
    lint val;
    bool fin;
    node(){fin = false; nxt.rs(2); nxt.asg(2, NULL); val = inf;}
};

node * proot, *sroot;

void trie_add(node * root, string & s, lint nv, bool suff){
    node * v = root;
    int n = s.length();
    if(!suff)
        root->val = min(root->val, nv);
    F(i, 0, n){
        int c = s[i] - '0';
        if(v->nxt[c] == NULL)
            v->nxt[c] = new node();
        v = v->nxt[c];
        if(!suff)
            v->val = min(v->val, nv);
    }
    v->val = min(v->val, nv);
    v->fin = true;
}

string rvs;

vector<int> calcz(string & ssr){
    int len = ssr.length();
    vector<int> rres;
    rres.rs(len); rres.asg(len, 0);
    rres[0] = 0;
    for(int i = 1, l = 0, r = 0; i < len; i++){
        if(r >= i)
            rres[i] = rres[i - l];
        int curr = rres[i];
        while((i + curr < len)  && (ssr[i + curr] == ssr[curr]))
            curr++;
        rres[i] = curr;
        if(rres[i] != 0){
            l = i; r = i + rres[i] - 1;
        }
    }
    ret rres;
}

void alt(){
        fp.rs(n);
    t.rs(n); c.rs(n); rt.rs(n); fs.rs(n);
    cin >> s;
    rs = s;
    reverse(rs.begin(), rs.end());
    zp.rs(n); zs.rs(n);
    F(i, 0, n){
        cin >> c[i];
        cin.get();
        cin >> t[i];
        rt[i] = t[i];
        reverse(rt[i].begin(), rt[i].end());
        fs[i] = rt[i] + '$' + rs;
        fp[i] = t[i] + '$' + rs;
        zs[i] = calcz(fs[i]);
        zp[i] = calcz(fp[i]);
    }
    dp.rs(m + 1);
    dp.asg(m + 1, inf);
    dp[0] = 0ll;
    root = build(0, m);
    F(i, 1, m + 1){
        F(j, 0, n){
            /*F(k, 1, min((int)t[j].length(), i) + 1){
                if(s.substr(i - k, k) == t[j].substr(0, k))
                    dp[i] = min(dp[i], dp[i - k] + c[j]);
                if(s.substr(i - k, k) == t[j].substr((int)t[j].length() - k, k))
                    dp[i] = min(dp[i], dp[i - k] + c[j]);
            }*/
            int coord = (t[j].length() + 1 + m - 1) - (i - 1);
            int lenp = min(min((int)t[j].length(), i), zp[j][coord]);
            int lens = min(min((int)t[j].length(), i), zs[j][coord]);
            dp[i] = min(dp[i], get(root, 0, m, i - lenp - 1, i - 1) + c[j]);
            dp[i] = min(dp[i], get(root, 0, m, i - lens - 1, i - 1) + c[j]);
        }
        upd(root, 0, m, i, dp[i]);
    }
    if(dp[m] == inf)
        printf("-1");
    else
        printf("%lld", dp[m]);
    exit(0);
}

int main(){
    string fin = fname + ".in";
    string fout = fname + ".out";
    freopen(fin.c_str(), "r", stdin);
    freopen(fout.c_str(), "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> m >> n >> L;
    if(n <= 20)
        alt();
    proot = new node;
    sroot = new node;
    t.rs(n); c.rs(n); rt.rs(n);
    cin >> s;
    rvs = s;
    reverse(rvs.begin(), rvs.end());
    F(i, 0, n){
        cin >> c[i];
        cin.get();
        cin >> t[i];
        rt[i] = t[i];
        reverse(rt[i].begin(), rt[i].end());
        trie_add(proot, t[i], c[i], false);
        //trie_add(sroot, rt[i], c[i]);
        F(j, 0, (int)t[i].length()){
            string tmp = t[i].substr(j);
            trie_add(sroot, tmp, c[i], true);
        }
    }
    dp.rs(m + 1);
    dp.asg(m + 1, inf);
    dp[0] = 0ll;
    F(i, 0, m){
        node * pv = proot;
        F(j, i + 1, m + 1){
            int c = s[j - 1] - '0';
            if(pv->nxt[c] == NULL)
                brk;
            pv = pv->nxt[c];
            dp[j] = min(dp[j], dp[i] + pv->val);
        }
        node * sv = sroot;
        F(j, i + 1, m + 1){
            int c = s[j - 1] - '0';
            if(sv->nxt[c] == NULL)
                brk;
            sv = sv->nxt[c];
            if(sv->fin)
                dp[j] = min(dp[j], dp[i] + sv->val);
        }
    }
    if(dp[m] == inf)
        printf("-1");
    else
        printf("%lld", dp[m]);
    ret 0;
}
