#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <cassert>

#pragma comment(linker, "/STACK:256000000")

using namespace std;

typedef long long int ll;
typedef long double ld;

const int INF = (1 << 29) + 5;
const ll LLINF = (1ll << 59) + 5;
const int MAX_N = 3000 * 100 + 5;

struct point
{
	string st;
	ll cost;
};

struct node
{
	int zero;
	int one;
	ll min_cost;

	node()
	{
		zero = -1;
		one = -1;
		min_cost = LLINF;
	}
};

int m, n, l;
point arr[MAX_N];
char st[MAX_N];
char add[MAX_N];
ll dp[MAX_N];
int len;
node bor[MAX_N * 8];
ll cost;
int sz = 1;

void add_st(int v, int ptr)
{
	if (ptr == len)
	{
		bor[v].min_cost = min(bor[v].min_cost, cost);
	}
	else
	{
		bor[v].min_cost = min(bor[v].min_cost, cost);
		if (add[ptr] == '0')
		{
			if (bor[v].zero == -1)
			{
				bor[v].zero = sz++;
			}
			add_st(bor[v].zero, ptr + 1);
		}
		else
		{
			if (bor[v].one == -1)
			{
				bor[v].one = sz++;
			}
			add_st(bor[v].one, ptr + 1);
		}
	}
}

int start;
void re_calc(int v, int ptr)
{
	if (ptr == m)
	{
		return;
	}
	else if (st[ptr] == '1')
	{
		if (bor[v].one != -1)
		{
			dp[ptr + 1] = min(dp[ptr + 1], dp[start] + bor[bor[v].one].min_cost);
			re_calc(bor[v].one, ptr + 1);
		}
	}
	else
	{
		if (bor[v].zero != -1)
		{
			dp[ptr + 1] = min(dp[ptr + 1], dp[start] + bor[bor[v].zero].min_cost);
			re_calc(bor[v].zero, ptr + 1);
		}
	}
}

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

	scanf("%d %d %d", &m, &n, &l);

	scanf("%s", st);

	for (int i = 0; i < n; ++i)
	{
		scanf("%lld %s", &cost, add);
		len = strlen(add);
		add_st(0, 0);
		for (int j = 1; j < len; ++j)
		{
			add_st(0, j);
		}
	}

	for (int i = 0; i <= m; ++i)
	{
		dp[i] = LLINF;
	}

	dp[0] = 0;
	for (int i = 0; i < m; ++i)
	{
		start = i;
		re_calc(0, i);
	}

	//for (int i = 0; i <= m; ++i)
	//{
	//	cout << dp[i] << " ";
	//}

	printf("%lld", (dp[m] == LLINF) ? -1ll : dp[m]);

	fclose(stdin);
	fclose(stdout);

	return 0;
}