#include <bits/stdc++.h>

using namespace std;

struct tree
{
    long long q;
    int l, r;
    tree(): q((long long)1e13), l(-1), r(-1) {}
};

tree mas1[(int)3e5 + 10], mas2[(int)3e5 + 10];
set<long long> s1, s2;
long long dp[50001];
long long mas[(int)12e5 + 10];
long long push[(int)12e5 + 10];
long long h[(int)3e5 + 10], po[(int)3e5 + 10];

void init(int v, int l, int r)
{
    if (r - l == 1)
    {
        mas[v] = dp[l];
        push[v] = dp[l];
        return;
    }
    int m = (l + r) / 2;
    init(2 * v + 1, l, m);
    init(2 * v + 2, m, r);
    mas[v] = min(mas[2 * v + 1], mas[2 * v + 2]);
    push[v] = (long long)1e18;
}

void pus(int v)
{
    mas[v] = min(mas[v], push[v]);
    push[2 * v + 1] = min(push[2 * v + 1], push[v]);
    push[2 * v + 2] = min(push[2 * v + 2], push[v]);
}

void ins(int v, int l, int r, int q, int w, long long t)
{
    if (l >= w || r <= q)
        return;
    if (q <= l && r <= w)
    {
        push[v] = min(push[v], t);
        return;
    }
    pus(v);
    int m = (l + r) / 2;
    ins(2 * v + 1, l, m, q, w, t);
    ins(2 * v + 2, m, r, q, w, t);
}

long long mn(int v, int l, int r, int q, int w)
{
    //cout << v << " " << mas[v] << " " << push[v] << " " << l << " " << r << " " << q << " " << w << endl;
    if (l >= w || r <= q)
        return (long long)1e18;
    if (q <= l && r <= w)
    {
        return min(mas[v], push[v]);
    }
    pus(v);
    int m = (l + r) / 2;
    return min(mn(2 * v + 1, l, m, q, w), mn(2 * v + 2, m, r, q, w));
}

const long long p = 239;
const long long mod = (long long)1e9 + 7;

long long modd(long long a)
{
    /*
    a = a % mod;
    if (a < 0)
        a += mod;
    //*/
    return a;
}

long long has(int l, int r)
{
    return modd(h[r] - h[l] * po[r - l]);
}

int main()
{
    freopen("typing.in", "r", stdin);
    freopen("typing.out", "w", stdout);
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    cin.tie(0);
    int m, n, L;
    cin >> m >> n >> L;
    string s;
    cin >> s;
    int num = 1;
    int lmax = 0;
    po[0] = 1;
    h[0] = 0;
    for (int i = 0; i < m; i++)
    {
        h[i + 1] = h[i] * p + s[i];
    }
    for (int i = 0; i < (int)3e5; i++)
    {
        po[i + 1] = po[i] * p;
    }
    for (int i = 0; i < n; i++)
    {
        long long q;
        string t;
        cin >> q >> t;
        int v = 0;
        int qwe = t.size();
        lmax = max(lmax, qwe);
        long long ha = 0;
        for (int i = 0; i < qwe; i++)
        {
            ha = ha * p + t[i];
            s1.insert(ha);
            if (t[i] == '0')
            {
                if (mas1[v].l == -1)
                {
                    mas1[v].l = num;
                    num++;
                }
                v = mas1[v].l;
            }
            else
            {
                if (mas1[v].r == -1)
                {
                    mas1[v].r = num;
                    num++;
                }
                v = mas1[v].r;
            }
            mas1[v].q = min(mas1[v].q, q);
        }
        v = 0;
        ha = 0;
        for (int i = qwe - 1; i >= 0; i--)
        {
            ha = ha + t[i] * po[qwe - 1 - i];
            s2.insert(ha);
            if (t[i] == '0')
            {
                if (mas2[v].l == -1)
                {
                    mas2[v].l = num;
                    num++;
                }
                v = mas2[v].l;
            }
            else
            {
                if (mas2[v].r == -1)
                {
                    mas2[v].r = num;
                    num++;
                }
                v = mas2[v].r;
            }
            mas2[v].q = min(mas2[v].q, q);
        }
    }
    for (int i = 0; i <= m; i++)
    {
        dp[i] = (long long)1e18;
    }
    dp[0] = 0;
    init(0, 0, m + 1);
    for (int i = 0; i <= m; i++)
    {
        if (lmax <= 2000)
        {
            if (i > 0)
            {
                int v = 0;
                for (int j = i - 1; j >= 0; j--)
                {
                    if (s[j] == '0')
                    {
                        if (mas2[v].l == -1)
                            break;
                        v = mas2[v].l;
                    }
                    else
                    {
                        if (mas2[v].r == -1)
                            break;
                        v = mas2[v].r;
                    }
                    dp[i] = min(dp[i], dp[j] + mas2[v].q);
                    if (mas2[v].q >= dp[i])
                        break;
                }
            }
            if (i < m)
            {
                int v = 0;
                for (int j = i; j < m; j++)
                {
                    if (s[j] == '0')
                    {
                        if (mas1[v].l == -1)
                            break;
                        v = mas1[v].l;
                    }
                    else
                    {
                        if (mas1[v].r == -1)
                            break;
                        v = mas1[v].r;
                    }
                    dp[j + 1] = min(dp[j + 1], dp[i] + mas1[v].q);
                }
            }
        }
        else
        {//*/
            //cout << i << endl;
            dp[i] = mn(0, 0, m + 1, i, i + 1);
            //cout << "(" << dp[i] << ")";
            if (i > 0)
            {
                int l = -1, r = i;
                while (r - l > 1)
                {
                    int qwe = (l + r) / 2;
                    if (s2.find(has(qwe, i)) != s2.end())
                        r = qwe;
                    else
                        l = qwe;
                }
                //cout << "1 " << l << " " << r << "   ";
                if (r < i)
                {
                    dp[i] = min(dp[i], mn(0, 0, m + 1, r, i) + 1);
                    ins(0, 0, m + 1, i, i + 1, dp[i]);
                }
            }
            //*/
            //cout << "(" << dp[i] << ")";
            if (i < m)
            {
                int l = i - 1, r = m;
                while (r - l > 1)
                {
                    int qwe = (l + r) / 2;
                    if (s1.find(has(i, qwe + 1)) != s1.end())
                        l = qwe;
                    else
                        r = qwe;
                }
                //cout << "2 " << l << " " << r;
                if (r > i)
                    ins(0, 0, m + 1, i + 1, l + 2, dp[i] + 1);
            }
            //*/
            //cout << endl;

        }
    }
    if (dp[m] > (long long)1e16)
        cout << -1 << "\n";
    else
        cout << dp[m] << "\n";
    return 0;
}
