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

using namespace std;
const int INF = 1e9;

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;
    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 <int> dp(m + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < m; ++i)
    {
        int j = i;
        node *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;
        }
        j = i;
        now = suff;
        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;
}
