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

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;

const int inf = 1000 * 1000 * 1000;
const ll inf64 = 1ll * inf * inf;

char buff[300300];

void read(string & s) {
	scanf("%s", &buff);
	s = buff;
}

int m, n, L;
vec< string > w;
vec< int > cost, preff, suff;
string big;

vec< vec< int > > pr, sf;
vec< int > add_vec;
int sz_preff, sz_suff;

void add_preff(int i) {
	int v = 0;
	for (int j = 0; j < (int)w[i].size(); j++) {
		int c = w[i][j] - '0';
		if (pr[v][c] == -1) {
			pr[v][c] = sz_preff++;
			pr.push_back(add_vec);
			preff.push_back(inf);
		}
		v = pr[v][c];
		preff[v] = min(preff[v], cost[i]);
	}
}

void add_suff(int i) {
	int v = 0;
	for (int j = (int)w[i].size() - 1; j >= 0;j--) {
		int c = w[i][j] - '0';
		if (sf[v][c] == -1) {
			sf[v][c] = sz_suff++;
			sf.push_back(add_vec);
			suff.push_back(inf);
		}
		v = sf[v][c];
		suff[v] = min(suff[v], cost[i]);
	}
}

void buildBor() {
	add_vec = vec< int >(2, -1);
	sz_preff = sz_suff = 1;
	preff.push_back(0);
	suff.push_back(0);
	pr.push_back(add_vec);
	sf.push_back(add_vec);
	for (int i = 0; i < n; i++) {
		add_preff(i);
		add_suff(i);
	}
}

bool solve() {

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

	scanf("%d %d %d", &m, &n, &L);

	read(big);

	w.resize(n);
	cost.resize(n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &cost[i]);
		read(w[i]);
	}

	buildBor();

	vec< ll > dp(m, inf64);
	
	for (int i = 0; i < m; i++) {
		for (int v = 0, j = i; j >= 0; j--) {
			int c = big[j] - '0';
			if (sf[v][c] == -1) break;
			v = sf[v][c];
			dp[i] = min(dp[i], (j ? dp[j - 1] : 0) + suff[v]);
		}
		for (int v = 0, j = i; j < m; j++) {
			int c = big[j] - '0';
			if (pr[v][c] == -1) break;
			v = pr[v][c];
			dp[j] = min(dp[j], (i ? dp[i - 1] : 0) + preff[v]);
		}
	}

	if (dp[m - 1] == inf64)
		printf("-1\n");
	else
		cout << dp[m - 1] << '\n';

	return true;
}

int main() {

	//while (solve());
	solve();

	return 0;
}