// A.cpp : Defines the entry point for the console application.
//

#include <fstream>
#include <vector>
#include <string>
#include <set>

using namespace std;

#define COUNT 2
#define P 11 
#define SIZE 100
#define START 10000000000000000

int f(long long i)
{
	long long j;
	for (j = 2; j * j <= i; j++)
		if (!(i % j))
			return 0;
	return 1;
}

int main()
{
	int n, m, i, j, k, h, q;
	string st, p, t, r;
	vector<int> ans, v;
	set <pair<vector<int>, int>> s;
	set <pair<vector<int>, int>>::iterator it;
	ifstream cin("typing.in");
	ofstream cout("typing.out");
	vector<long long> mod, gen;
	vector<vector<long long>> pow;
	long long w;
	for (i = START; gen.size() < SIZE; i++)
		if (f(i))
			gen.push_back(i);
	while (mod.size() < COUNT)
		mod.push_back(gen[rand() % gen.size()]);
	j = 1;
	for (k = 0; k < COUNT; k++)
	{
		pow.push_back({});
		for (i = 0; i < 5010; i++)
		{
			pow[k].push_back(j);
			j = (j * P) % mod[k];
		}
	}

	cin >> m >> n >> i >> st;
	for (i = 0; i < n; i++)
	{
		cin >> k >> p;
		t = p;
		while (t.size())
		{
			v.clear();
			for (q = 0; q < COUNT; q++)
			{
				w = 0;
				for (h = t.size() - 1; h >= 0; h--)
					w = (w + pow[q][t.size() - 1 - h] * t[h]) % mod[q];
				v.push_back(w);
			}
			it = s.upper_bound(make_pair(v, -1));
			if (it == s.end() || it->first != v)
				s.insert(make_pair(v, k));
			else if (it->second > k)
			{
				s.insert(make_pair(v, k));
				s.erase(it);
			}
			t.pop_back();
		}

		for (j = 1; j < p.size(); j++)
		{
			t.clear();
			for (h = j; h < p.size(); h++)
				t.push_back(p[h]);
			v.clear();
			for (q = 0; q < COUNT; q++)
			{
				w = 0;
				for (h = t.size() - 1; h >= 0; h--)
					w = (w + pow[q][t.size() - 1 - h] * t[h]) % mod[q];
				v.push_back(w);
			}
			it = s.upper_bound(make_pair(v, -1));
			if (it == s.end() || it->first != v)
				s.insert(make_pair(v, k));
			else if (it->second > k)
			{
				s.insert(make_pair(v, k));
				s.erase(it);
			}
		}
	}

	ans.push_back(0);
	for (i = 1; i <= m; i++)
	{
		ans.push_back(1e9);
		for (q = 0; q < COUNT; q++)
			v[q] = 0;
		for (j = i - 1; j >= 0; j--)
		{
			for (q = 0; q < COUNT; q++)
				v[q] = (v[q] + pow[q][i - 1 - j] * st[j]) % mod[q];
			it = s.upper_bound(make_pair(v, -1));
			if (it != s.end() && it->first == v && ans[j] + it->second < ans[i])
			{
				ans[i] = ans[j] + it->second;
			}
		}
	}

	if (ans[m] >= 1e9)
		cout << -1 << endl;
	else
		cout << ans[m] << endl;
	cout.close();
}

