#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
ifstream in("typing.in");
ofstream out("typing.out");

struct elem {
	elem* u[2] = { nullptr, nullptr };
	int cost = 179179179;
};
elem t;

void add(int c, string & s) {
	elem* cur = &t;
	for (int i = 0; i < s.size(); ++i) {
		if (cur->u[s[i] - '0'] == nullptr) {
			cur->u[s[i] - '0'] = new elem;
		}
		cur = cur->u[s[i] - '0'];
		cur->cost = min(cur->cost, c);
	}
}

int f(string & s, int i, int curcost) {
	if (i == s.size())
		return curcost;
	elem*cur = &t;
	int r = 179179179;
	while (cur != nullptr) {
		if (i == s.size() || cur->u[s[i] - '0'] == nullptr || cur->cost < cur->u[s[i] - '0']->cost)
			r = min(r, f(s, i, curcost + cur->cost));
		if (i < s.size())
			cur = cur->u[s[i] - '0'];
		else
			break;
		++i;
	}
	return r;
}

int main()
{
	int m, n, l;
	in >> m >> n >> l;
	string s;
	in >> s;
	for (int i = 0; i < n; ++i) {
		int c;
		in >> c;
		string s;
		in >> s;	
		add(c, s);
		reverse(s.begin(), s.end());
		add(c, s);
	}
	int r = f(s, 0, 0);
	out << (r >= 179179179 ? -1 : r);
}