#include <fstream>
#include <string>
#include <bitset>
#include <vector>
#include <algorithm>

#define mp make_pair
#define ff first 
#define ss second

using namespace std;

using value_t = long long;
const value_t INF = 1ll << 61;

int main() {
	ifstream fin("typing.in");
	ofstream fout("typing.out");
	int m, n, L; fin >> m >> n >> L;
	string line; fin >> line;
	vector<pair<string, int>> seq(n);
	for (auto& s : seq) {
		fin >> s.ss >> s.ff;
	}
	sort(seq.begin(), seq.end());
	vector<value_t> dp(m + 1, INF);
	dp[0] = 0;
	for (int i = 1; i <= m; ++i) {
		int lb = 0, rb = n - 1;
		for (int j = 1; j <= i; ++j) {
			char ch = line[i - j];
			if (ch == '0') {
				while (rb >= lb && 
					(j - 1 >= seq[rb].ff.length() ||
						seq[rb].ff[j - 1] != ch))
					--rb;
			}
			else {
				while (rb >= lb && 
					(j - 1 >= seq[lb].ff.length() ||
					seq[lb].ff[j - 1] != ch))
					++lb;
			}
			if (lb > rb) break;
			value_t min_val = INF;
			for (int i = lb; i <= rb; ++i)
				min_val = min(min_val, 1ll*seq[i].ss);
			dp[i] = min(dp[i], dp[i - j] + min_val);
		}
	}
	fout << (dp[m] == INF ? -1 : dp[m]) << "\n";
	return 0;
}