#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <vector>
#include <string>

using namespace std;

const long long INF = 100000000000000000;
const long long N = 300000;
struct node {
	long long min;
	node *left, *right;
	node(long long new_min) {
		min = new_min;
		left = right = nullptr;
	}
};
long long get_min(node *root) {
	if (root == nullptr) {
		return INF;
	}
	return root->min;
}
void comb(node *root) {
	root->min = min(min(get_min(root->left), get_min(root->right)), root->min);
}
node* insert(node *root, string &s, long long ind, long long cost) {
	if (root == nullptr) {
		root = new node(INF);
	}
	if (ind == s.size()) {
		root->min = min(root->min, cost);
		return root;
	}
	if (s[ind] == '0') {
		root->left = insert(root->left, s, ind + 1, cost);
		comb(root);
		return root;
	}
	else {
		root->right = insert(root->right, s, ind + 1, cost);
		comb(root);
		return root;
	}
}
long long dp[N];

int main()
{
	freopen("typing.in", "r", stdin);
	freopen("typing.out", "w", stdout);

	long long m, n, l;
	cin >> m >> n >> l;
	string s;
	cin >> s;
	string g = s;
	s = ' ' + s;
	reverse(g.begin(), g.end());
	g = ' ' + g;
	node *root = nullptr;
	node *suff = nullptr;
	for (long long i = 0; i < n; i++) {
		long long cost;
		cin >> cost;
		string p;
		cin >> p;
		root = insert(root, p, 0, cost);
		reverse(p.begin(), p.end());
		suff = insert(suff, p, 0, cost);
	}
	dp[0] = 0;
	for (long long i = 1; i <= m; i++) {
		dp[i] = INF;
	}
	for (long long i = 1; i <= m; i++) {
		node *cur_suff = suff;
		node *cur = root;
		for (long long j = i; j >= 1; j--) {
			if (cur_suff != nullptr) {
				if (s[j] == '0') {
					cur_suff = cur_suff->left;
				}
				else {
					cur_suff = cur_suff->right;
				}
			}
			dp[i] = min(dp[i], dp[j - 1] + get_min(cur_suff));
		}

		for (long long j = i; j <= m; j++) {
			
			if (s[j] == '0') {
				cur = cur->left;
			}
			else {
				cur = cur->right;
			}
			if (cur == nullptr) {
				break;
			}
			dp[j] = min(dp[j], dp[i - 1] + get_min(cur));
		}
	}
	if (dp[m] >= INF) {
		cout << -1 << endl;
	}
	else {
		cout << dp[m] << endl;
	}
	//for (;;);
}

/*

9 2 8
000110100
1 100
1 11001

*/