program Z8;

{$APPTYPE CONSOLE}

uses
  SysUtils;
  var m,n,l,i,p,y,j,qw:longint;
     s1:string;
     c:array [1..1000] of longint;
     s:array [1..1000] of string;
     a:Array [0..1000,0..1000] of longint;
begin
  assign(input,'typing.in');
  reset(input);
  readln(m,n,l);
  readln(s1);
  for i:=1 to n do
   begin
   readln(c[i],s[i]);
    delete(s[i],1,1);
   end;
   close(input);
   assign(output,'typing.out');
   rewrite(output);
    if s[1][1]=s1[1] then a[1,1]:=c[1]
     else
    if s[1][length(s[1])]=s1[1] then a[1,1]:=c[1]
     else a[1,1]:=-1;
    for i:=1 to m do
     a[0,i]:=0;
     for i:=1 to n do
      for j:=1 to m do
       begin
          if (i=1)and(j<>1) then
           begin
             if a[i,j-1]=-1 then a[i,j]:=-1
              else
               begin
                y:=0;
                 for p:=length(s[i]) downto 1 do
                    begin
                      if p<=j then
                       begin
                         if copy(s[i],1,p)=copy(s1,j-p+1,p) then y:=p
                          else if copy(s[i],length(s[i])-p+1,p)=copy(s1,j-p+1,p) then y:=p;
                          if y=p then break;
                       end;


                    end;
                    if y=0 then a[i,j]:=-1
                     else a[i,j]:=c[i]+a[i,j-y];

               end;

           end;
          if i<>1 then
           begin
            if a[i,j-1]=-1 then a[i,j]:=-1
              else
               begin
                y:=0;
                 for p:=length(s[i]) downto 1 do
                    begin
                      if p<=j then
                       begin
                         if copy(s[i],1,p)=copy(s1,j-p+1,p) then y:=p
                          else if copy(s[i],length(s[i])-p+1,p)=copy(s1,j-p+1,p) then y:=p;
                          if y=p then break;
                       end;


                    end;
                    if y=0 then a[i,j]:=-1
                     else a[i,j]:=c[i]+a[i,j-y];
                    if (a[i-1,j]<>-1)and((a[i-1,j]<a[i,j])or(a[i,j]=-1)) then a[i,j]:=a[i-1,j];
                   if a[i-1,j]<>-1 then
                    begin
                      for qw:=1 to j-1 do
                       if a[i-1,j]-a[i-1,j-qw]<a[i,j]-a[i,j-qw] then a[i,j]:=a[i-1,j]-a[i-1,j-qw]+a[i,j-qw]

                    end;
               end;
           end;



       end;

    writeln(a[n,m]);



   close(output);
end.
