#include <bits/stdc++.h>

using namespace std;

struct tree
{
    long long q;
    int l, r;
    tree(): q((long long)1e13), l(-1), r(-1) {}
};

tree mas1[(int)3e5 + 10], mas2[(int)3e5 + 10];
long long dp[10001];

int main()
{
    freopen("typing.in", "r", stdin);
    freopen("typing.out", "w", stdout);
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    cin.tie(0);
    int m, n, L;
    cin >> m >> n >> L;
    string s;
    cin >> s;
    int num = 1;
    for (int i = 0; i < n; i++)
    {
        long long q;
        string t;
        cin >> q >> t;
        int v = 0;
        for (int i = 0; i < t.size(); i++)
        {
            if (t[i] == '0')
            {
                if (mas1[v].l == -1)
                {
                    mas1[v].l = num;
                    num++;
                }
                v = mas1[v].l;
            }
            else
            {
                if (mas1[v].r == -1)
                {
                    mas1[v].r = num;
                    num++;
                }
                v = mas1[v].r;
            }
            mas1[v].q = min(mas1[v].q, q);
        }
        v = 0;
        for (int i = t.size() - 1; i >= 0; i--)
        {
            if (t[i] == '0')
            {
                if (mas2[v].l == -1)
                {
                    mas2[v].l = num;
                    num++;
                }
                v = mas2[v].l;
            }
            else
            {
                if (mas2[v].r == -1)
                {
                    mas2[v].r = num;
                    num++;
                }
                v = mas2[v].r;
            }
            mas2[v].q = min(mas2[v].q, q);
        }
    }
    for (int i = 0; i <= m; i++)
    {
        dp[i] = (long long)1e18;
    }
    dp[0] = 0;
    for (int i = 0; i <= m; i++)
    {
        if (i > 0)
        {
            int v = 0;
            for (int j = i - 1; j >= 0; j--)
            {
                if (s[j] == '0')
                {
                    if (mas2[v].l == -1)
                        break;
                    v = mas2[v].l;
                }
                else
                {
                    if (mas2[v].r == -1)
                        break;
                    v = mas2[v].r;
                }
                dp[i] = min(dp[i], dp[j] + mas2[v].q);
            }
        }
        if (i < m)
        {
            int v = 0;
            for (int j = i; j < m; j++)
            {
                if (s[j] == '0')
                {
                    if (mas1[v].l == -1)
                        break;
                    v = mas1[v].l;
                }
                else
                {
                    if (mas1[v].r == -1)
                        break;
                    v = mas1[v].r;
                }
                dp[j + 1] = min(dp[j + 1], dp[i] + mas1[v].q);
            }
        }
    }
    if (dp[m] == (long long)1e18)
        cout << -1 << endl;
    else
        cout << dp[m] << endl;
    return 0;
}
