#include<stdio.h>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<iostream>
#include<set>
#include<math.h>
#include<algorithm>

#pragma warning (disable:4996)

#define ll long long int
#define mp make_pair

using namespace std;

ll n, m, l, mod = 1e9 + 7, x, c[300005], d[300005], hh[300005], deg[300005], h[300005];
map<ll, ll> st;
string t, s[300005];

void f(ll k) {
	ll i, tt, r;
	tt = x;
	r = s[k].size();
	for (i = 0; i < r; i++) {
		if (i == 0) {
			h[i] = tt*((ll)(s[k][i] - '0' + 1));
		}
		else {
			h[i] = h[i - 1] + tt*((ll)(s[k][i] - '0' + 1));
		}
		h[i] %= mod;
		tt *= x;
		tt %= mod;
	}
	for (i = 0; i < r; i++) {
		if (st[h[i] * deg[300000] % mod] == 0) {
			st[h[i] * deg[300000] % mod] = c[k];
		}
		else {
			st[h[i] * deg[300000] % mod] = min(st[h[i] * deg[300000] % mod], c[k]);
		}
		if (st[(h[r - 1] - h[i] + mod) % mod*deg[300000 - i - 1] % mod] == 0) {
			st[(h[r - 1] - h[i] + mod) % mod*deg[300000 - i - 1] % mod] = c[k];
		}
		else {
			st[(h[r - 1] - h[i] + mod) % mod*deg[300000 - i - 1] % mod] = min(st[(h[r - 1] - h[i] + mod) % mod*deg[300000 - i - 1] % mod], c[k]);
		}
	}
}

void solve() {
	ll i, j, q, w, tt,e;
	vector<ll> v;
	map<ll, vector<ll> > u;
	map<ll, vector<ll> >::iterator it;
	x = 239;
	deg[0] = 1;
	d[0] = 1e18;
	for (i = 1; i < 300005; i++) {
		deg[i] = deg[i - 1] * x;
		deg[i] %= mod;
		d[i] = 1e18;
	}
	cin >> t;
	for (i = 0; i < n; i++) {
		cin >> c[i] >> s[i];
	}
	for (i = 0; i < n; i++) {
		f(i);
	}
	tt = x;
	for (i = 0; i < m; i++) {
		if (i == 0) {
			hh[i] = tt*((ll)(t[i] - '0' + 1));
		}
		else {
			hh[i] = hh[i - 1] + tt*((ll)(t[i] - '0' + 1));
		}
		hh[i] %= mod;
		tt *= x;
		tt %= mod;
	}
	if (m <= 5000) {
		for (i = 0; i < m; i++) {
			w = hh[i];
			w *= deg[300000];
			w %= mod;
			q = st[w];
			if (q > 0) {
				d[i] = min(d[i], q);
			}
			else {
				st.erase(w);
			}
			for (j = 0; j < i; j++) {
				w = (hh[i] - hh[j] + mod) % mod;
				w *= deg[300000 - j - 1];
				w %= mod;
				q = st[w];
				if (q > 0) {
					d[i] = min(d[i], d[j] + q);
				}
				else {
					st.erase(w);
				}
			}
		}
	}
	else {
		for (i = 0; i < m; i++) {
			w = hh[i];
			w *= deg[300000];
			w %= mod;
			q = st[w];
			if (q > 0) {
				d[i] = min(d[i], q);
			}
			else {
				st.erase(w);
			}
			e = 0;
			for (it = u.begin(); it != u.end()&&e==0; it++) {
				for (j = 0; j < it->second.size(); j++) {
					q = it->second[j];
					w = (hh[i] - hh[q] + mod) % mod;
					w *= deg[300000 - q - 1];
					w %= mod;
					tt = st[w];
					if (tt > 0) {
						d[i] = min(d[i], d[q] + tt);
						v.push_back(q);
						e = 1;
					}
					else {
						st.erase(w);
					}
				}
				it->second = v;
				v.clear();
			}
			if (d[i] == 1e18) {
				i = 1e9;
			}
			u[d[i]].push_back(i);
		}
	}
	if (d[m - 1] == 1e18) {
		printf("-1");
	}
	else {
		printf("%I64d", d[m - 1]);
	}
	return;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#else
	freopen("typing.in", "rt", stdin);
	freopen("typing.out", "wt", stdout);
#endif
	scanf("%I64d%I64d%I64d", &m, &n, &l);
	solve();
	return 0;
}