#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iterator>
#define next lkadsjflasdjfl
using namespace std;

const int maxN = 3000;
const int maxM = 50000;
const int INF = (int)1e9 + 7;

long long d[maxM + 1];

struct node
{
	int mn;
	node *l, *r;

	node()
	{
		mn = INF;
		l = 0;
		r = 0;
	}
};

node *nroot = new node(), *rroot = new node();

node* pushn(string::iterator it, string::iterator end, int cost, node *v = nroot)
{
	if (v == 0)
	{
		v = new node();
	}

	v->mn = min(v->mn, cost);
	if (it == end)
	{
		return v;
	}
	if (*it == '0')
	{
		v->l = pushn(++it, end, cost, v->l);
	}
	else
	{
		v->r = pushn(++it, end, cost, v->r);
	}
	return v;
}

node* pushr(string::iterator it, string::iterator end, int cost, node *v = rroot)
{

	if (v == 0)
	{
		v = new node();
	}

	v->mn = min(v->mn, cost);
	if (it == end)
	{
		return v;
	}
	if (*it == '0')
	{
		v->l = pushr(++it, end, cost, v->l);
	}
	else
	{
		v->r = pushr(++it, end, cost, v->r);
	}
	return v;
}

node* next(node* v, char c)
{
	if (c == '0')
	{
		return v->l;
	}
	else
	{
		return v->r;
	}
}


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

	int m, n, l;
	cin >> m >> n >> l;

	string s;
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		string curr;
		int c;
		cin >> c >> curr;
		nroot = pushn(curr.begin(), curr.end(), c);
		reverse(curr.begin(), curr.end());
		rroot = pushr(curr.begin(), curr.end(), c);
	}

	for (int i = 1; i <= m; i++)
	{
		d[i] = INF;
	}

	for (int i = 0; i <= m; i++)
	{
		node* curr = rroot;

		for (int j = i; j > 0; j--)
		{
			curr = next(curr, s[j - 1]);
			if (curr == 0)
			{
				break;
			}
			d[i] = min(d[i], d[j - 1] + curr->mn);
		}

		curr = nroot;

		for (int j = i + 1; j <= m; j++)
		{
			curr = next(curr, s[j - 1]);
			if (curr == 0)
			{
				break;
			}
			d[j] = min(d[j], d[i] + curr->mn);
		}
	}

	if (d[m] == INF)
	{
		cout << -1;
	}
	else
	{
		cout << d[m];
	}


	
    return 0;
}

