Uses
  Math;
Const
  osn:int64=5;
  md=1000000007;
Type
  mass=array[0..40000]of int64;
  msss=array[1..2000]of mass;
Var
  n,m,l,c,tkh,mxlen,qwe,ind:int64;i,j,tk:longint;
  s,q:string;
  ch:char;
  st:array[0..300000]of int64;
  hs,cost:msss;
  dp:array[0..300000]of int64;
Procedure Swap(Var a,b:int64);
Var
  c:int64;
Begin
  c:=a;
  a:=b;
  b:=c;
end;
Procedure qSort(Var m1,m2:mass;l,r:int64);
Procedure sort(l,r:int64);
Var
  i,j,sr,x1,x2:int64;
Begin
  i:=l;j:=r;
  sr:=i+random(j-i+1);
  x1:=m1[sr];x2:=m2[sr];
  repeat
    while (m1[i]<x1)or((m1[i]=x1)and(m2[i]<x2))do inc(i);
    while (x1<m1[j])or((x1=m1[j])and(x2<m2[j]))do dec(j);
    if i<=j then
      begin
        if i<j then
          begin
            Swap(m1[i],m1[j]);
            Swap(m2[i],m2[j]);
          end;
        inc(i);dec(j);
      end;
  until i>j;
  if i<r then
    sort(i,r);
  if l<j then
    sort(l,j);
end;
begin
  randomize;
  sort(l,r);
end;
Function bs(Var m:mass;x:int64;l,r:longint):longint;
Var
  sr,an:longint;
Begin
  an:=-1;
  while l<=r do
    begin
      sr:=(l+r)div 2;
      if m[sr]=x then
        begin
          an:=sr;
          break;
        end
      else
        if m[sr]>x then
          r:=sr-1
        else
          l:=sr+1;
    end;
  bs:=an;
end;
begin
//  assign(input,'input.txt');assign(output,'output.txt');
  assign(input,'typint.in');assign(output,'typing.out');
  readln(m,n,l);
  readln(s);
  st[0]:=1;
  for i:=1 to m do
    st[i]:=(st[i-1]*osn)mod md;
  mxlen:=0;
  for i:=1 to n do
    begin
      read(c);
      read(ch);
      readln(q);
      mxlen:=max(mxlen,length(q));
      tkh:=0;
      for j:=1 to min(length(q),m) do
        begin
          tkh:=(tkh+(ord(q[j])-ord('/'))*st[j])mod md;
          inc(hs[j,0]);
          hs[j,hs[j,0]]:=tkh;
          cost[j,hs[j,0]]:=c;
        end;
      tkh:=0;
      tk:=0;
      for j:=length(q) downto max(1,length(q)-m+1) do
        begin
          inc(tk);
          tkh:=((tkh+(ord(q[j])-ord('/')))*st[1])mod md;
          inc(hs[tk,0]);
          hs[tk,hs[tk,0]]:=tkh;
          cost[tk,hs[tk,0]]:=c;
        end;
    end;
  for i:=1 to min(mxlen,m) do
    begin
      qSort(hs[i],cost[i],1,hs[i,0]);
      qwe:=hs[i,0];
      hs[i,0]:=0;
      for j:=1 to qwe do
        if hs[i,j]<>hs[i,j-1] then
          begin
            inc(hs[i,0]);
            hs[i,hs[i,0]]:=hs[i,j];
            cost[i,hs[i,0]]:=cost[i,j];
          end;
    end;
  dp[0]:=0;
  for i:=1 to m do
    begin
      dp[i]:=high(int64);
      tkh:=(st[1]*(ord(s[i])-ord('/')))mod md;
      tk:=1;
      for j:=i-1 downto 1 do
        begin
          if dp[j]<>high(int64) then
            begin
              ind:=bs(hs[tk],tkh,1,hs[tk][0]);
              if ind<>-1 then
                dp[i]:=min(dp[i],dp[j]+cost[tk,ind]);
            end;
          inc(tk);
          tkh:=((ord(s[j])-ord('/')+tkh)*osn)mod md;
        end;
      ind:=bs(hs[tk],tkh,1,hs[tk][0]);
      if ind<>-1 then
        dp[i]:=min(dp[i],dp[0]+cost[tk,ind]);
    end;
  if dp[m]=high(int64) then
    writeln(-1)
  else
    writeln(dp[m]);
end.
