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

using namespace std;

typedef long long nagai;

bool deb = 0;

int solve(int n, int m, int L, string s, vector<int> ws, vector<string> ss)
{
	vector<vector<int>> gopref(2), gosuff(2);
	vector<int> wpref, wsuff;
	wpref.push_back(0);
	wsuff.push_back(0);
	gopref[0].push_back(-1);
	gopref[1].push_back(-1);
	gosuff[0].push_back(-1);
	gosuff[1].push_back(-1);
	m = s.size();
	for (auto& x : s)
		x -= '0';
	for (int i = 0; i < n; ++i)
	{
		int w = ws[i];
		for (auto& x : ss[i])
			x -= '0';
		string s1 = ss[i];
		int cur = 0, cur1 = 0;
		int c = 0;
		while (c < s1.size() && cur != -1)
			wpref[cur] = min(wpref[cur], w), cur1 = cur, cur = gopref[s1[c]][cur], ++c;
		if (cur == -1)
			cur = cur1, --c;
		else
			wpref[cur] = min(wpref[cur], w);
		for (c; c < s1.size(); ++c)
			gopref[0].push_back(-1), gopref[1].push_back(-1), gopref[s1[c]][cur] = gopref[0].size() - 1, wpref.push_back(w), cur = gopref[0].size() - 1;

		reverse(s1.begin(), s1.end());

		cur = 0, c = 0;
		while (c < s1.size() && cur != -1)
			wsuff[cur] = min(wsuff[cur], w), cur1 = cur, cur = gosuff[s1[c]][cur], ++c;
		if (cur == -1)
			cur = cur1, --c;
		else
			wsuff[cur] = min(wsuff[cur], w);
		for (c; c < s1.size(); ++c)
			gosuff[0].push_back(-1), gosuff[1].push_back(-1), gosuff[s1[c]][cur] = gosuff[0].size() - 1, wsuff.push_back(w), cur = gosuff[0].size() - 1;
	}
	nagai INF = 1000000000000000000LL;
	vector<nagai> dp(m + 1, INF);
	dp[0] = 0;
	for (int i = 0; i <= m; ++i)
	{
		if (i > 0)
		{
			int cur = gosuff[s[i - 1]][0], j = i - 1;
			while (cur != -1 && j >= 0)
			{
				dp[i] = min(dp[i], dp[j] + wsuff[cur]);
				if (j - 1 >= 0)
					cur = gosuff[s[j - 1]][cur];
				--j;
			}
		}
		int cur = 0, j = i;
		while (cur != -1 && j <= m)
		{
			dp[j] = min(dp[j], dp[i] + wpref[cur]);
			if (j < m)
				cur = gopref[s[j]][cur];
			++j;
		}
	}
	if (deb)
	{
		vector<nagai> dp1(m + 1, INF);
		dp1[0] = 0;
		for (int i = 0; i < m; ++i)
		{
			for (int j = 0; j < n; ++j)
				for (int k = 0; k < ss[j].size(); ++k)
				{
					if (i + k <= m && ss[j].substr(0, k) == s.substr(i, k))
						dp1[i + k] = min(dp1[i + k], dp1[i] + ws[j]);
					if (i + ss[j].size() - k <= m && ss[j].substr(k, ss[j].size() - k) == s.substr(i, ss[j].size() - k))
						dp1[i + ss[j].size() - k] = min(dp1[i + ss[j].size() - k], dp1[i] + ws[j]);
				}
		}
		if (dp1[m] != dp[m])
		{
			cerr << "MEME" << endl;
		}
		if (dp1[m] == INF)
			return -1;
		return dp1[m];
	}
	if (dp[m] == INF)
		return -1;
	return dp[m];
}

string genstr(int len)
{
	string s;
	for (int i = 0; i < len; ++i)
		s.push_back('0' + (rand() & 1));
	return s;
}

int main1()
{
	for (int i = 0; i < 1000; ++i)
	{
		int m = rand() % 2 + 1;
		int n = rand() % 2 + 1;
		string s = genstr(m);
		vector<int> ws(n);
		for (auto& x : ws)
			x = rand() % 5 + 1;
		vector<string> ss(n);
		for (auto& x : ss)
			x = genstr(rand() % 2 + 1);
		solve(n, m, 0, s, ws, ss);
	}
	return 0;
}

int main()
{
	ifstream cin("typing.in");
	ofstream cout("typing.out");
	int m, n, L; cin >> m >> n >> L;
	string s; cin >> s;
	vector<int> ws(n);
	vector<string> ss(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> ws[i] >> ss[i];
	}
	cout << solve(n, m, L, s, ws, ss) << endl;
	return 0;
}