#include <bits/stdc++.h>

#define TASK "twopaths"
using namespace std;
typedef long long ll;
typedef long double ld;

struct node
{
    ll next[2];
    ll mincost;

    node() : mincost(1e17)
    { next[0] = next[1] = -1; };
};

node mas[345678];
ll pend = 1;
ll dp[345678];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    if(strcmp(TASK,"")!=0)
    {
        freopen(TASK".in","r",stdin);
        freopen(TASK".out","w",stdout);
    }
#endif
    ll m, n, l;
    cin >> m >> n >> l;
    string s;
    cin >> s;
    for(int i=0;i<345678;i++)
    {
        dp[i] = 1e17;
    }
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        ll c;
        cin >> c;
        string t;
        cin >> t;
        ll cur = 0;
        ll curpos = 0;
        while (curpos < t.size())
        {
            if (mas[cur].next[t[curpos] - '0'] == -1)
            {
                mas[cur].next[t[curpos] - '0'] = pend;
                pend++;
            }
            cur = mas[cur].next[t[curpos] - '0'];
            if (mas[cur].mincost > c)
            {
                mas[cur].mincost = c;
            }
            curpos++;
        }
        cur = 0;
        curpos = t.size() - 1;
        while (curpos >= 0)
        {
            if (mas[cur].next[t[curpos] - '0'] == -1)
            {
                mas[cur].next[t[curpos] - '0'] = pend;
                pend++;
            }
            cur = mas[cur].next[t[curpos] - '0'];
            if (mas[cur].mincost > c)
            {
                mas[cur].mincost = c;
            }
            curpos--;
        }
    }
    for (int i = 0; i < s.size(); i++)
    {
        ll cur = 0;
        ll curpos = i;
        while (curpos < s.size() && mas[cur].next[s[curpos] - '0'] != -1)
        {
            cur = mas[cur].next[s[curpos] - '0'];
            dp[curpos+1] = min(dp[curpos+1],dp[i] + mas[cur].mincost);
            curpos++;
        }
    }
    for(int i=0;i<=s.size();i++)
    {
        //cout << dp[i] << " ";
    }
    if(dp[s.size()]>1e16)
    {
        cout << -1;
    }
    else cout << dp[s.size()];
    return 0;
}