#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <cstring>

using namespace std;

bool s[50013];
bool a[50013][2013];
long long c[50013];
long long out[50013];
int n, m, L;
char x[50013];
int siz_a[50013];
char e;
int main() {
	//freopen("1.txt", "r", stdin);
	freopen("typing.in", "r", stdin);
	freopen("typing.out", "w", stdout);

	scanf("%d%d%d", &n, &m, &L);
	scanf("%c", &e);
	cin.getline(x, 50013);

	int z = strlen(x);
	for (int i = 0; i < z; i++) {
		s[i] = (x[i] == '1');
	}

	for (int i = 0; i <= n; i++) {
		out[i] = 1000000000000000000;
	}

	for (int i = 0; i < m; i++) {
		scanf("%d%c", &c[i], &e);
		cin.getline(x, 50013);
		siz_a[i] = strlen(x);
		for (int j = 0; j < siz_a[i]; j++) {
			a[i][j] = (x[j] == '1');
		}
	}

	out[0] = 0;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			int ind1 = 1;
			int k1 = i - ind1;
			int k2 = siz_a[j] - ind1;
			while (ind1 <= siz_a[j] && ind1 <= i && s[k1] == a[j][k2]) {
				out[i] = min(out[i], out[k1] + c[j]);
				ind1++;
				k2--;
				k1--;
			}
		}
		for (int j = 0; j < m; j++) {
			int ind2 = 0;
			while (ind2 < siz_a[j] && ind2 < n - i && s[ind2 + i] == a[j][ind2]) {
				out[ind2 + i + 1] = min(out[ind2 + i + 1], out[i] + c[j]);
				ind2++;
			}
		}
	}

	if (out[n] >= 10000000000000000) {
		cout << -1 << endl;
		return 0;
	}
	printf("%ll\n", out[n]);
	return 0;
}