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

using namespace std;

#define lint long long int

#define C 300005

#define inf 1000000000

map<string, int> cost;

struct pt
{
	int curCost;
	pt *zero, *one;
};

pt root;


lint d[C];

lint D(int x)
{
	if (x < 0)
		return 0;
	return d[x];
}

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

	int n, m, L;
	cin >> m >> n >> L;
	string s;
	cin >> s;

	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		string s0;
		cin >> s0;
		string s1;
		pt *cur = &root;
		for (int i = 0; i < s0.size(); i++)
		{
			if (s0[i] == '0')
			{
				if (cur->zero == 0) {
					cur->zero = new pt;
					cur->zero->zero = 0;
					cur->zero->one = 0;
					cur->zero->curCost = inf;
				}
				cur = cur->zero;
			}
			if (s0[i] == '1')
			{
				if (cur->one == 0) {
					cur->one = new pt;
					cur->one->zero = 0;
					cur->one->one = 0;
					cur->one->curCost = inf;
				}
				cur = cur->one;
			}
			cur->curCost = min(cur->curCost, a);

			/*s1.push_back(s0[i]);
			if (cost.find(s1) != cost.end())
				cost[s1] = a;
			else
				cost[s1] = min(a, cost[s1]);*/
		}
		cur = &root;
		for (int i = s0.size() - 1; i >= 0; i--)
		{
			if (s0[i] == '0')
			{
				if (cur->zero == 0) {
					cur->zero = new pt;
					cur->zero->zero = 0;
					cur->zero->one = 0;
					cur->zero->curCost = inf;
				}
				cur = cur->zero;
			}
			if (s0[i] == '1')
			{
				if (cur->one == 0) {
					cur->one = new pt;
					cur->one->zero = 0;
					cur->one->one = 0;
					cur->one->curCost = inf;
				}
				cur = cur->one;
			}
			cur->curCost = min(cur->curCost, a);

			/*s1.push_back(s0[i]);
			if (cost.find(s1) != cost.end())
			cost[s1] = a;
			else
			cost[s1] = min(a, cost[s1]);*/
		}

		string s2;
		for (int i = s0.size() - 1; i >= 0; i--)
		{
			/*s2.push_back(s0[i]);
			if (cost.find(s2) != cost.end())
				cost[s2] = a;
			else
				cost[s2] = min(a, cost[s2]);*/
		}
	}

	for (int i = 0; i < s.size(); i++)
	{
		lint res = 1000000000;
		pt *cur = &root;
		for (int j = i; j >= 0; j--)
		{
			if (s[j] == '0')
				cur = cur->zero;
			else
				cur = cur->one;
			if (cur == NULL)
				break;
			res = min(D(j - 1) + cur->curCost, res);
		}
		d[i] = res;

		//cout << d[i] << " ";
	}
	if (d[s.size() - 1] < inf)
		cout << d[s.size() - 1];
	else
		cout << -1;

	fclose(stdin);
	fclose(stdout);
	return 0;
}