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

using namespace std;

typedef long long nagai;

int main()
{
	ifstream cin("typing.in");
	ofstream cout("typing.out");
	int m, n, L; cin >> m >> n >> L;
	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);
	string s; cin >> s;
	for (auto& x : s)
		x -= '0';
	for (int i = 0; i < n; ++i)
	{
		int w; cin >> w;
		string s1; cin >> s1;
		for (auto& x : s1)
			x -= '0';
		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;
		cur = cur1, --c;
		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;
		cur = cur1, --c;
		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]), cur = gopref[s[j]][cur], ++j;
	}
	if (dp[m] == INF)
		cout << -1 << endl;
	else
		cout << dp[m] << endl;
}