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

using namespace std;

#define lint long long int

#define C 50005

#define inf 1000000000000000000

map<string, lint> cost;

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

pt root;


lint d[C];

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

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

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

	for (lint i = 0; i < n; i++)
	{
		lint a;
		cin >> a;
		string s0;
		cin >> s0;
		string s1;

		for (int j = 0; j < s0.size(); j++) {
			pt *cur = &root;
			/*for (lint i = j; 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;
				}
				if(j == 0 || i == s0.size() - 1)
				cur->curCost = min(cur->curCost, a);

				
			}*/
			cur = &root;
			for (lint i = s0.size() - 1 - j; 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;
				}
				if (j == 0 || i == 0)
				cur->curCost = min(cur->curCost, a);

				
			}

		}

		string s2;
		for (lint 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 (lint i = 0; i < s.size(); i++)
	{
		lint res = inf;
		pt *cur = &root;
		for (lint 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] << " ";
	}
	cout << endl;
	if (d[s.size() - 1] < inf)
		cout << d[s.size() - 1];
	else
		cout << -1;

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