#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxm = 10002;
const int maxL = 50002;
const int lmax = 1002;
const ll inf = (ll)1e9 + 100;
ll cost[maxL];
ll dp[maxm];
bool TEXT[maxm];
bool s[maxL][lmax];
int len[maxL];
int m, n, L;

char str[maxL];

int main() {
    freopen("typing.in", "r", stdin);
    freopen("typing.out", "w", stdout);
    scanf("%d %d %d", &m, &n, &L);
    scanf("%s", str);
    for (int i = 1; i <= m; ++i) TEXT[i] = (str[i - 1] == '1');
    for (int i = 0; i < n; ++i) {
        scanf("%I64d", &cost[i]);
        scanf("%s", str);
        len[i] = strlen(str);
        for (int j = 0; j < len[i]; ++j) {
            s[i][j] = (str[j] == '1');
        }
    }
    for (int i = 1; i <= m; ++i) dp[i] = inf;
    dp[0] = 0;
    for (int i = 0; i <= m; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < len[j]; ++k) {
                if (TEXT[i + 1 + k] != s[j][k]) break;
                dp[i + 1 + k] = min(dp[i + 1 + k], dp[i] + cost[j]);
            }
            for (int k = len[j] - 1; k >= 0; --k) {
                //if (TEXT[i + 1 + len[j] - 1 - k] != s[j][k]) break;
                bool ok = 1;
                for (int p = k; p < len[j]; ++p) {
                    if (TEXT[i + 1 + p - k] != s[j][p]) {
                        ok = 0;
                        break;
                    }
                }
                if (ok) dp[i + 1 + len[j] - 1 - k] = min(dp[i + 1 + len[j] - 1 - k], dp[i] + cost[j]);
            }
        }
    }
    cout << (dp[m] < inf ? dp[m] : -1);
    return 0;
}

/*
9 3 10
010110101
3 0101
10 011
2 100

2 2 5
01
1 10
1 111
*/
