var m,x1,y1,sum,k,x2,i,j,n,k1,k2,k3,k4,n1,n2,max,x,y : longint;
s,s2: string;
cccc:array[0..100] of longint;
a,c:array[1..2000] of longint;

begin
  readln(n,m);
  readln(s);
     for i :=1 to n do
     a[i]:=ord(s[i])-ord('a')+1;

     for i :=1 to n do
                for j :=1 to n do
                if a[i]<a[j] then begin
                x:=a[i];
                a[i]:=a[j];
                a[j]:=x;
                end;
                 j:=1;
                 i:=2;
                 k1:=a[1];
                 sum:=a[1];
        while (j<m) and (i<=n) do
             begin
             if a[i]-k1>1 then
             begin
             sum:=sum+a[i];
             j:=j+1;
               k1:=a[i];
             end;
             i:=i+1;
             end;
   if j <m then
   write(-1) else
 write(sum);
end.

var q:char;k,n,z,x,i:longint;a:array[0..33]of longint;s:string;
begin
 s:='';
 for  q:='a' to 'z' do
 s:=s+q;
 readln(n,k);
 for i:=1 to n do
 begin
 read(q);
 a[pos(q,s)]:=1;

 end;
 z:=0;
 i:=1;x:=0;
 while i<=26 do
 begin
  while (a[i]=0) and(i<=26) do inc(i);
  if i<=26 then begin
   z:=z+i;inc(i);inc(x);
   if k=x then begin write(z);halt;end;
  end;
  inc(i);
 end;
 write(-1);
end.

var
a:array[1..26]of integer;
i,n,k,kk,mas:integer;
s,z:string;
begin
s:='abcdefghijklmnopqrstuvwxyz';
read(n);
readln(k);
read(z);
for i:=1 to length(z) do begin
a[pos(z[i],s)]:=1;
end;
kk:=0;
i:=1;
mas:=0;
while (kk<k)and(i<27) do begin

if a[i]=1 then begin
kk:=kk+1;
mas:=mas+i;
i:=i+1;
end;
i:=i+1;

end;

if kk=k then writeln(mas) else writeln(-1);
end.

var n,m,i,s,x:longint;k,ch,c:char;
f:array['a'..'z'] of boolean;
begin
//assign(input,'jd.in');reset(input);
//assign(output,'jd.out');rewrite(output);
readln(n,m);c:=succ('z');
for i:=1 to n do
  begin
  read(ch);
  if ch<c then c:=ch;
  f[ch]:=true;
  end;
x:=1;s:=ord(c)-96;
for k:='a' to 'z' do
  if(f[k])and(ord(k)-ord(c)>=2)then
    begin
    if x=m then break;
    c:=k;x:=x+1;s:=s+ord(k)-96;
    end;
if x=m then writeln(s) else writeln(-1);
close(input);close(output);
end.

var n,m,i,t,s:longint;c:char;
a:ansistring;
procedure sort(l,r: longint);
var i,j: longint;x,y:char;
begin
i:=l;j:=r;x:=a[(l+r) div 2];
repeat
  while a[i]<x do inc(i);
  while x<a[j] do dec(j);
  if not(i>j) then
    begin
    y:=a[i];a[i]:=a[j];a[j]:=y;
    inc(i);j:=j-1;
    end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
//assign(input,'jd.in');reset(input);
//assign(output,'jd.out');rewrite(output);
readln(n,m);
readln(a);
sort(1,n);
t:=1;
for i:=1 to m do
  if t<=n then
    begin
    s:=s+ord(a[t])-ord('a')+1;c:=a[t];
    while (t<=n) and (ord(a[t])-ord(c)<2) do
      inc(t);
    end
  else
    begin
    writeln(-1);
    close(input);
    close(output);
    halt;
    end;
writeln(s);
close(input);close(output);
end.

program ideone;
var n,k,i,ko,kn,sum:integer;
	a:array[1..100] of integer;
	s:char;
begin
	readln(n,k);
	for i:=1 to n do
	begin
		read(s);
		inc(a[ord(s)-96]);
	end;
	ko:=0;
	kn:=-10;
	i:=1;
	sum:=0;
	for i:=1 to 26 do
	begin
		if (a[i]<>0)AND(i<>kn+1) then begin
										kn:=i;
										inc(ko);
										sum:=sum+i;
									end;
		if ko=k then break;
	end;
	if ko=k then writeln(sum)
			else writeln(-1);

end.

var
   ans,n,k,i,p,j:longint;
   s,t:string;
   a:array[1..1000] of longint;
procedure qsort (l,r:longint);
var
   x,y,m,k:longint;
begin
   x:=l;
   y:=r;
   m:=a[(x+y)div 2];
   repeat
      while (a[x]<m) do inc(x);
      while (a[y]>m) do dec(y);
      if x<=y then
      begin
          k:=a[y];
          a[y]:=a[x];
          a[x]:=k;
          inc(x);
          dec(y);
      end;
   until x>y;
   if l<y then qsort(l,y);
   if x<r then qsort(x,r);
end;

begin
   readln (n,k);
   readln(s);
   t:='abcdefghijklmnopqrstuvwxyz';
   for i:=1 to n do
      a[i]:=pos(s[i],t);
   qsort (1,n);
   i:=1;
   j:=0;
   p:=a[i];
   ans:=0;
   while (i<=n)and (j<k) do
   begin
      ans:=ans+a[i];
      p:=p+2;
      inc(i);
      inc(j);
      if j=k then break;
      while (a[i]<p)and (i<n) do inc(i);
      if p>a[i] then begin ans:=-1; break; end;
      p:=a[i];
   end;
   writeln (ans);
end.

{$Coperators ON}
{			  meoww~~~ meoww~~~
		  /\___/\
		 ( =^.^= )
		  (") (")_/
}
uses math;
var n,k:Longint;
	s:string;
procedure init;
var i,j,t:Longint;
	tam:char;
begin
	readln(n,k);
	readln(s);
	for i:=1 to Length(s) do
		for j:=i+1 to Length(s) do
			if s[j]<s[i] then
				begin
					tam:=s[i];
					s[i]:=s[j];
					s[j]:=tam;
				end;
	t:=ord(s[1])-96;
	tam:=s[1];
	dec(k);
	if k=0 then
				begin
					writeln(t);
					exit;
				end;
	for i:=2 to n do
	if ord(s[i])-ord(tam)>=2 then
		begin
			tam:=s[i];
			t+=ord(s[i])-96;
			dec(k);
			if k=0 then
				begin
					writeln(t);
					exit;
				end;
		end;
	writeln(-1);
end;
begin
assign(input,''); reset(input);
assign(output,''); rewrite(output);

init;
close(input);
close(output);
end.

var
  n,i,j,t,m,ans:longint;
  k,p:char;
  a:array['a'..'z'] of longint;
  f:array['a'..'z',0..50] of longint;
function min(x,y:longint):longint;
  begin
    if x>y
      then exit(y)
      else exit(x);
  end;
begin
  readln(n,m);
  for i:=1 to n do
    begin
      read(p);
      a[p]:=1;
    end;
  for k:='a' to 'z' do
    f[k,0]:=0;
  for i:=1 to m do
    for k:='a' to 'z' do
      f[k,i]:=maxlongint div 2;
  for i:=1 to m do
    begin
      if a['a']=1
        then f['a',1]:=1;
      if a['b']=1
        then f['b',1]:=2;
      for k:='c' to 'z' do
        if a[k]=1
          then
            begin
              for p:='a' to chr(ord(k)-2) do
                if f[p,i-1]<maxlongint div 2
                  then f[k,i]:=min(f[k,i],f[p,i-1]);
              f[k,i]:=f[k,i]+ord(k)-ord('a')+1;
            end;
    end;
  ans:=maxlongint div 2;
  for k:='a' to 'z' do
    ans:=min(ans,f[k,m]);
  if ans<maxlongint div 2
    then writeln(ans)
    else writeln(-1);
end.

var
x,kol,j,n,k,i,ans,min:longint;
a:array[-10..100000]of longint;
s:string;
begin
readln(n,k);
readln(s);

for i:=1 to lengtH(s) do begin
    inc(a[ord(s[i])-96]);
end;
//for i:=1 to 26 do write(a[i],' ');
min:=100000000;
for i:=1 to 26 do begin
    j:=i;
    ans:=i;
    kol:=1;
    x:=i;
    if a[i]>=1 then begin
    while true do begin
         inc(j);
         if kol>=k then break;
         if j>26 then break
         else begin
              if (j-x>=2)and(a[j]>=1) then begin
                  inc(kol);
                  inc(ans,j);
                  x:=j;
              end;

         end;
    end;
    if kol=k then begin
        if ans<min then min:=ans;
    end;
    end;
end;
if min = 100000000 then writeln(-1)
else
writeln(min);
end.

type tabel=array['a'..'z'] of longint;
var c:char;
    n,i,j,p,k,nr,sol:longint;
    s:string;
    t:tabel;
begin
readln(n,k);
readln(s);
for i:=1 to length(s) do
inc(t[s[i]]);
s:='';
for c:='a' to 'z' do
for j:=1 to t[c] do s:=s+c;
i:=2; nr:=1;
c:=s[1]; sol:=sol+ord(s[1])-96;
while (nr<k) and (i<=length(s)) do
begin
if ord(s[i])-ord(c)>1 then begin
c:=s[i];
sol:=sol+ord(c)-96;
inc(nr) end;
inc(i) end;
if nr<k then write(-1) else write(sol)
end.

var
  n, k: integer;
  s, h: string;
  count: integer;

begin
  readln(n, k);
  readln(s);
  var ar: array of integer = new integer[n];
  for var i := 0 to n - 1 do
    ar[i] := ord(s[i + 1]);
  Sort(ar);
  h := chr(ar[0]);
  for var i := 1 to k - 1 do
  begin
    var b := false;
    for var j := 1 to n - 1 do
    begin
      if ar[j] > ord(h[h.Length]) + 1 then
      begin
        b := true;
        h += chr(ar[j]);
        break;
      end;
    end;
    if b = false then count := -1;
  end;
  if count <> -1 then
  begin
    for var i := 1 to k do
      count += ord(h[i]) - ord('a') + 1;
    writeln(count);
  end
  else
    writeln(count);
end.

program olymp;
var
  s,alf : string;
  z : char;
  n,k,i,j,sum,kol,nom : longint;
begin
  readln(n,k);
  readln(s);
    for j:=1 to n do
  for i:=1 to n-1 do
    if s[i]>s[i+1]
      then begin
        z:=s[i];
        s[i]:=s[i+1];
        s[i+1]:=z;
      end;
  alf:='abcdefghijklmnopqrstuvwxyz';
  nom:=1;
  kol:=1;
  sum:=pos(s[1],alf);
  for i:=2 to n do begin
      //writeln(pos(s[i],alf));
      if pos(s[i],alf)-pos(s[kol],alf)>=2
        then begin
          if nom=k
          then break;
          inc(nom);
          sum:=sum+pos(s[i],alf);
          kol:=i;
        end;
  end;
  if nom=k
  then writeln(sum)
  else writeln('-1');
end.

var s:string; l:char;
    n,k,j,i,p,k1:integer;
begin
readln(n,k);
read(s);
for i:=1 to n do
for j:=1 to n-1 do
if s[j]>s[j+1] then begin l:=s[j]; s[j]:=s[j+1]; s[j+1]:=l; end;
p:=ord(s[1])-96; j:=ord(s[1]);
for i:=2 to n do
begin if k1+1=k then break;
if ord(s[i])>j+1 then begin
p:=p+ord(s[i])-96;
j:=ord(s[i]);
k1:=k1+1;
end;
end;
if k1+1=k then write(p) else write(-1);
end.

program Project4;
var
  N,K,i,j,w,min,max,pos : Integer;
  s : String;
  bln : Boolean;
  A : array[1..50]of integer;
begin
  Readln(N,K);
  Readln(s);
  For i:=1 to N do A[i]:=Ord(s[i])-96;
  w:=0; min:=0; bln:=TRUE;
  For i:=1 to K do
  begin
    max:=27;
    pos:=0;
    For j:=1 to N do
    begin
      if (A[j]<max)and(A[j]>min) then
      begin
        max:=A[j];
        pos:=j;
      end;
    end;
    if pos>0 then
    begin
      w:=w+A[pos];
      min:=A[pos]+1;
      A[pos]:=27;
    end else bln:=FALSE;
  end;
  if bln then writeln(w) else writeln(-1);
end.

 var i,j,n,k,ans:longint;
  s:string;
  x:char;
   begin
  readln (n,k);
   read (s);

  for i:=1 to n do
   for j:=i+1 to n do
    if s[i]>s[j] then
     begin
      x:=s[i];
      s[i]:=s[j];
      s[j]:=x;
     end;

  x:=' ';

  for i:=1 to n do
   begin
    if ord(s[i])-ord(x)>1 then
     begin
      dec (k);
      inc (ans,ord(s[i])-ord('a')+1);
      x:=s[i];
     end;
    if k=0 then
     begin
      writeln (ans);
      halt;
     end;

   end;

  writeln (-1);

   end.

Var
    n, k, x, Ans, pos: Integer;
    a: Array [1..26] of Integer;
    S: String;

Begin
    Read(n);
    Readln(k);
    Readln(S);
    pos := 1;
    For Var i := 1 to n do
        a[ord(S[i]) - 96] := 1;
    While pos <= 26 do Begin
        If (a[pos] = 1) then Begin
            Ans += pos;
            pos += 2;
            x += 1;
            If x = k then Begin
                Write(Ans);
                Exit
            End
        End
        Else
            pos += 1
    End;
        Write(-1)
End.

var
  n, k, i: integer;

var
  a: array [1..26] of integer;

var
  min: integer;

var
  ch: char;

function CreatMInRocket(m: integer): integer;
var
  i, j, naid, last, r: integer;
var
  b: array [1..26] of integer;
begin
  r := m;
  naid := 1;
  for i := 1 to 26 do b[i] := a[i];
  last := m;
  dec(b[m]);
  j := 1;

  while (naid <> k) and (r < 1000000000) do
  begin
  j := 1;
    while (((j - last) < 2) or (b[j] = 0)) and (j < 26) do inc(j);

    if (j = 26) and (b[26] = 0) or (j - last < 2)  then r := 1000000000 else
    begin
      inc(naid);
      r += j;
      dec(b[j]);
      last := j;
    end;

  end;
  result := r;
end;

begin
  readln(n, k);

  for i := 1 to n do
  begin
    read(ch);
    inc(a[ord(ch) - 96]);
  end;

  min := 1000000000;
  for i := 1 to 26 do
  if (a[i] <> 0) and (CreatMInRocket(i) < min) then min := CreatMInRocket(i);
  if (min = 1000000000) or (n < k) then min := -1;
  writeln(min);
end.

var
sum,min,min1,n,k,s1,s2,p1,p2:longint;
a:string;
b: array [1..50] of longint;
begin
sum:=0;
Readln(n,k);
Readln(a);

for s1:=1 to n do
  b[s1]:=ord(a[s1])-96;
min:=b[1];
min1:=1;
s1:=0;
while (s1<>k) and (min1<=26) do
  begin
  for s2:=1 to n do
    if (b[s2]<min) and (b[s2]>=min1) then
      min:=b[s2];
  if min=100 then begin Writeln(-1); exit; end;
  min1:=min+2;
  sum+=min;
  min:=100;
  s1:=s1+1;
  end;
if s1=k then
Writeln(sum) else Writeln(-1);
end.

Program p;
var n, k, j, res: integer;
    a: array of integer;
    h: char;

begin
readln(n, k);
setlength(a, n);
for var g:=0 to n-1 do
  begin
  read(h);
  a[g]:=ord(h)-96
  end;
sort(a);
res:=a[0];
j:=0;
k-=1;
for var g:=1 to n-1 do
  begin
  if k=0 then break;
  if a[g]-a[j]<2 then
    else
      begin
      j:=g;
      k-=1;
      res+=a[j]
      end
  end;
if k>0 then write(-1)
  else write(res)
end.

      const eps=0.00000001;  besk1=200000008;  nn=10600000;
             { modul=1000000007;  }
   besk=8000000000000000000;
   label 22,1,2,3,4;
    type    real=extended;   double=extended;  int64=longint;
    mas=array [-100000..nn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3 :int64;end; zap1=^zap;
    mass=array[-10..nn] of longint;mass1=^mass;
    var limit,posi,posj,diam,modul,oldt,ot1,time,pos,prod,ll,rr,posx,posy,gr,n,dloch,newdl,oldn,oldm,ost,ot,aa,bb,cc,p1,p2,p3,p4,kk,znamzz,kolperiod,znam,tperiod,start,finish,kol1,kol2,lavel,x0,p0,t2,t1,jj,w,ii,ogr,q,p,pp,tt,oldtt,qq,qq1,qq2,q1,q2,pmax,imax,t,nm,m,smin,cen:int64;
   pp0,mask,k,i1,j1,step1, step, i,j:longint;
   y:mas;
    ppp,prob1,prob2,prob3,pr1new,pr2new,pr3new,pr1,pr2,pr3:zap;
    izb,oldpos,finot,vv,znak:int64;
    aold:mas;
    xplus,xminus,px,py,xc,yc,xxc,yyc:extended;
    del:array[-1..1000001,-1..10] of longint;
    kolright,a,fact,next,prev,x,xx,yy,str,kol,s,name,d,dnew, voltay,l,r,c,z,day,b:mas;
    zzsum,zz:array[-10..12500000] of int64;
    ppole:array[-10..1002,-10..1005] of char;
    pole,ddd,dd1,dd2,dd3,dd4,dd,ddsum:array[-10..1201,-10..1220] of int64;
   newzan,marked,zanx,zany:array[-1000000..2000000] of boolean;
    sss1,sss2:string;
    udal,dl,och,newoch,place,stoim,nabor:array[-10..1200005] of int64;
     zanleft,zanright,zan,fl:array[-100000..10000000] of boolean;
    ss1,ss2,ss:string;ch,ch1,ch2:char;
    binkoef,numleft,numright,dr: array [-10..60,-10..60] of int64;
    s3,s2,s1:array[-100..200000] of string;

    grr :array [-10..2010,-10..2010] of boolean;
    maxpr:array[0..nn] of string;
    sss:array[-10..nn] of string;
     tx,ty,vel,x1,y1,ott,v0,v1,s0,t0:int64;
     zv:point;
     ugol,rot,temp,sumtemp,vol,newx,newy:array[-1000..400000] of int64;
     sq,sqx,sqy,ottt,aaa,bbb,ccc:extended;
     xxx,yyy,yot:double;
       flag2,flag,flag1:boolean;

  function max(a,b:int64):int64;
begin max:=a; if b>a then max:=b;   end;

  function min(a,b:int64):int64;
begin min:=a; if b<a then min:=b;   end;

      function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

     function summ(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p2+xx.p2*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=t1 div tt mod modul;
    t2:=t2 div tt mod modul;
    ott.p1:=t1; ott.p2:=t2;

   summ:=@ott;
 end;

{     function prod(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=(t1 div tt) mod modul;
    t2:=(t2 div tt) mod modul;
    ott.p1:=t1; ott.p2:=t2;

   prod:=@ott;
 end;
 }

    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p{/pi*180};
 end;

function degg(a,k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k shr 1); degg:=p*p mod modul;   end;

end;

{function prost(tt:longint):boolean;
var aa:extended; i,p,t:longint;  fl:boolean;
 begin
   fl:=true;
   aa:=tt;
   aa:=sqrt(aa);
   t:=round(aa);
   for i:=2 to t do if tt mod i=0 then fl:=false;

   prost:=fl;
 end;
 }
function arcsin(pp:extended):extended;
var tt:extended;
begin
   if (abs(pp)<=1+eps)and (abs(pp)>=1-eps)
   then if pp>0 then arcsin:=pi/2 else arcsin:=-pi/2;
   tt:=1-pp*pp;
   if abs(tt)>=0 then
     begin
        arcsin:=arctan(pp/sqrt(tt));

     end;

end;

function gl(ch:char):boolean;
begin
 if (ch='o')or (ch='a')or(ch='e')or(ch='u')or(ch='i') then gl:=true else gl:=false;

end;

begin

   { assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
    }
      readln(n,k); readln(ss);
      for i:=1 to n do zan[ord(ss[i])-ord('a')+1]:=true;
      pos:=-2;        ot:=0;
      for step:=1 to k do
        begin
           flag:=false;
           for i:=pos+2 to 26 do if zan[i] then begin flag:=true;ii:=i; break; end;
         {  writeln(flag,' ii= ', ii);
         }  if flag then begin inc(q);  end else begin write(-1); goto 1; end;
           pos:=ii;
              ot:=ot+ii;

        end;

          if q<k then begin writeln(-1); goto 1; end

      else writeln(ot);

   1:          close(output);
end.

{$Coperators ON}
{			  meoww~~~ meoww~~~
		  /\___/\
		 ( =^.^= )
		  (") (")_/
}
uses math;
var n,k:Longint;
	s:string;
procedure init;
var i,j,t:Longint;
	tam:char;
begin
	readln(n,k);
	readln(s);
	for i:=1 to Length(s) do
		for j:=i+1 to Length(s) do
			if s[j]<s[i] then
				begin
					tam:=s[i];
					s[i]:=s[j];
					s[j]:=tam;
				end;
	t:=ord(s[1])-96;
	tam:=s[1];
	dec(k);
	if k=0 then
				begin
					writeln(t);
					exit;
				end;
	for i:=2 to n do
	if ord(s[i])-ord(tam)>2 then
		begin
			tam:=s[i];
			t+=ord(s[i])-96;
			dec(k);
			if k=0 then
				begin
					writeln(t);
					exit;
				end;
		end;
	writeln(-1);
end;
begin
assign(input,''); reset(input);
assign(output,''); rewrite(output);

init;
close(input);
close(output);
end.

program olymp;
var
  s,alf : string;
  z : char;
  n,k,i,j,sum,kol,nom : longint;
begin
  readln(n,k);
  readln(s);
    for j:=1 to n do
  for i:=1 to n-1 do
    if s[i]>s[i+1]
      then begin
        z:=s[i];
        s[i]:=s[i+1];
        s[i+1]:=z;
      end;
  alf:='abcdefghijklmnopqrsutvwxyz';
  nom:=1;
  kol:=1;
  sum:=pos(s[1],alf);
  for i:=2 to n do begin
      //writeln(pos(s[i],alf));
      if pos(s[i],alf)-pos(s[kol],alf)>=2
        then begin
          if nom=k
          then break;
          inc(nom);
          sum:=sum+pos(s[i],alf);
          kol:=i;
        end;
  end;
  if nom=k
  then writeln(sum)
  else writeln('-1');
end.

 var i,j,n,k,x,ans:longint;
 c:char;
 a:array [1..51] of longint;
  begin
   readln (n,k);

  for i:=1 to n do
   begin
    read (c);
    a[i]:=ord(c)-ord('a')+1;
   end;

   for i:=1 to n do
    for j:=i+1 to n do
     if a[i]>a[j] then
      begin
       x:=a[i];
       a[i]:=a[j];
       a[j]:=x;
      end;

 ans:=a[1];
 dec (k);
  for i:=2 to n do
   begin
    if k=0 then
     begin
      writeln (ans);
      halt;
     end;

    if a[i]-a[i-1]>1 then
     begin
      dec (k);
      inc (ans,a[i]);
     end;

   end;

   if k=0 then writeln (ans)
          else writeln (-1);

  end.

Var
    n, k, x, Ans: Integer;
    a: Array [1..26] of Integer;
    S: String;

Begin
    Read(n);
    Readln(k);
    Readln(S);
    For Var i := 1 to n do
        a[ord(S[i])-96] := 1;
    For Var i := 1 to 26 do
        If (a[i] <> 0) and ((i = 1) or (a[i - 1] = 0)) then Begin
            x += 1;
            Ans += i;
            If x = k then Begin
                Write(Ans);
                Exit
            End
        End;
        Write(-1)
End.

var
  n, k, i: integer;

var
  a: array [1..26] of integer;

var
  min: integer;

var
  ch: char;

function CreatMInRocket(m: integer): integer;
var
  i, j, naid, last, r: integer;
var
  b: array [1..26] of integer;
begin
  r := m;
  naid := 1;
  for i := 1 to 26 do b[i] := a[i];
  last := m;
  dec(b[m]);
  j := 1;

  while (naid <> k) and (r < 1000000000) do
  begin
  j := 1;
    while (((j - last) <= 2) or (b[j] = 0)) and (j < 26) do inc(j);

    if (j = 26) and (b[26] = 0) or (j - last <= 2)  then r := 1000000000 else
    begin
      inc(naid);
      r += j;
      dec(b[j]);
      last := j;
    end;

  end;
  result := r;
end;

begin
  readln(n, k);

  for i := 1 to n do
  begin
    read(ch);
    inc(a[ord(ch) - 96]);
  end;

  min := 1000000000;
  for i := 1 to 26 do
  if (a[i] <> 0) and (CreatMInRocket(i) < min) then min := CreatMInRocket(i);
  if (min = 1000000000) then min := -1;
  writeln(min);
end.

var
sum,min,min1,n,k,s1,s2,p1,p2:longint;
a:string;
b: array [1..50] of longint;
begin
sum:=0;
Readln(n,k);
Readln(a);

for s1:=1 to n do
  b[s1]:=ord(a[s1])-96;
min:=b[1];
min1:=1;
s1:=0;
while (s1<>k) and (min1<=26) do
  begin
  for s2:=1 to n do
    if (b[s2]<min) and (b[s2]>=min1) then
      min:=b[s2];
  if min=100 then begin Writeln(-1); exit; end;
  min1:=min+2;
  sum+=min;
  min:=100;
  s1:=s1+1;
  end;
Writeln(sum);
end.


var n,i,j,w,k,t:longint;
f:array[0..501,0..501] of longint;
s:ansistring;
begin
//assign(input,'qczfc.in');reset(input);
//assign(output,'qczfc.out');rewrite(output);
readln(n);
readln(s);
for i:=1 to n do f[i,i]:=1;
for i:=2 to n do
  for t:=1 to n-i+1 do
    begin
    w:=t+i-1;
    f[t,w]:=maxlongint;
    for k:=t to w-1 do
      if f[t,k]+f[k+1,w]-ord(s[t]=s[w])<f[t,w] then
        f[t,w]:=f[t,k]+f[k+1,w]-ord(s[t]=s[w]);
    end;

write(f[1,n]);
close(input);close(output);
end.

var n,i,j,w,k,t:longint;
f:array[1..500,1..500] of longint;
s:string;
begin
//assign(input,'qczfc.in');reset(input);
//assign(output,'qczfc.out');rewrite(output);
readln(n);
readln(s);
for i:=1 to n do f[i,i]:=1;
for i:=1 to n-1 do
  for t:=1 to n-i do
    begin
    w:=t+i;
    f[t,w]:=999999999;
    for k:=t to w-1 do
      if f[t,k]+f[k+1,w]-ord(s[t]=s[w])<f[t,w] then
        f[t,w]:=f[t,k]+f[k+1,w]-ord(s[t]=s[w]);
    end;

write(f[1,n]);
end.

var n,i,j,w,k,t:longint;
f:array[1..500,1..500] of longint;
s:string;
begin
//assign(input,'qczfc.in');reset(input);
//assign(output,'qczfc.out');rewrite(output);
readln(n);
readln(s);
for i:=1 to n do f[i,i]:=1;
for i:=2 to n do
  for t:=1 to n-i+1 do
    begin
    w:=t+i-1;
    f[t,w]:=999999999;
    for k:=t to w-1 do
      if f[t,k]+f[k+1,w]-ord(s[t]=s[w])<f[t,w] then
        f[t,w]:=f[t,k]+f[k+1,w]-ord(s[t]=s[w]);
    end;

write(f[1,n]);
end.

                                          const eps=1e-10;
      besk=8000000000000000000; label 1,3,2,44;
type mas=array[-10000..550000+1] of int64; integer=longint;
var len,i1,j1,mask,stepp,h,n2,i,j,k,l,step,k1,w,mesto,num:longint;
ss,ss1:string;
dx,dy,ll,rr,sum,m,start,finish,time,p3,p4,jj,qqq,ii,tt,pmax,pmax2,qq,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,n,nn,kk,modul,t0,t1,n1,t2,q,t,p:int64; flag1:boolean;
  summ,place,kol,str,a2,b2,left,right,zz,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
 jmax,maxx, gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
  marked,zan:array[-10..1000000] of boolean;
  a1,b1,strok:array[-10..550000] of int64;
  stroka:array[-1000..1000000] of char;
  ot1,otmax,v:extended;
  sp,sss:array[-10..2000000] of string;
  newpole,dd,pole:array[-100..1210,-1..1210] of int64;
  dchet,dnech,poschet,posnechet:array[-10..290000,-1..30] of int64;
  pos:int64;
  ch:char;
  flagg1:boolean;
  ymax,ymin,xmax,xmin,znach,z,nomer,newplace,newstr,s,next,prev,xx,yy,aold,x,y:array[-100000..2000002] of int64;
  ddd:array[-10..5010,-10..5010] of int64;
 function srav(i,j:longint):boolean;
  begin if (a[i]<a[j])or(a[i]=a[j])and(a1[i]<a1[j])or(a[i]=a[j])and(a1[i]=a1[j])and(a2[i]<a2[j])  then
  srav:=true else srav:=false; end;

procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
until (k>=n);

end;

function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

function phi(a,b:double):double; label 222;var p:double;
begin
  if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
  if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
  if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
  if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
  if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
  222: phi:=p;
end;

function nod(a,b:int64):int64; var p,t:int64;
begin
  a:=abs(a); b:=abs(b);
  if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
nod:=p;
end;

function nok(a,b:int64):int64;
begin  nok:=(a*b) div nod(a,b);  end;

   function degg(a:int64;k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
   begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

end;

procedure udal(ii:longint);
begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

function nomerr(gr:int64):int64;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=p;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<=gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,p+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
   { if fl then nomerr:=a1[cc] else nomerr:=-1000;}
   nomerr:=cc;
end;

 function vhodit(t:int64):boolean;
var sum,ii,jj,p:int64;  ans:boolean;
begin
   p:=t;
   for i:=1 to t do a[i]:=x[i];
    n:=1;
    repeat n:=n*2 until n>=p;
         for i:=p+1 to n+2 do a[i]:=besk;
        sort(a);
    { for i:=1 to p do write(a[i],' '); writeln;
     }
     sum:=0;
    if not odd(t) then
     for i:=1 to t div 2 do sum:=sum+a[2*i] else
     for i:=1 to (t+1) div 2 do sum:=sum+a[2*i-1];
    { writeln('sum= ',sum);
     }
 ans:=sum<=hh;
vhodit:=ans;
end;

function prost(pp:longint):boolean;
var i,j,t:longint; tt:extended; fl:boolean;
begin
  tt:=pp;
  tt:=sqrt(tt);
  fl:=true;
  for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

 prost:=fl;

end;

function check(t:int64):boolean;
var tmin,ll,rr,kol,tt,i,j,k:longint; flag,fl:boolean;
begin
   tmin:=0;
   for i:=1 to n do
     begin
        ll:=a[i];rr:=a[i]+t;
        if (tmin>=ll)and(tmin<=rr) then begin   end;

     end;

end;

begin

  { assign (input,'D:\Projects\input.txt');reset(input);
   assign (output,'D:\Projects\output.txt'); rewrite(output);
   }

    readln(n);
    readln(ss);
    for i:=1 to n do for j:=1 to n do dd[i,j]:=besk;
    for i:=1 to n do dd[i,i]:=1;
    for len:=2 to n do for i:=1 to n-len+1 do
       begin
           p1:=i; p2:=i+len-1;
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2-1]+1);
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]);
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]);

           if ss[p1]=ss[p1+1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]);
           if ss[p2]=ss[p2-1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]+1);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]+1);
           for j:=p1+1 to p2-1 do if (ss[p1]=ss[j])and(ss[j]=ss[p2])and(dd[p1,j]>1)or(dd[j,p2]>1) then
            dd[p1,p2]:=min(dd[p1,p2],dd[p1,j]+dd[j,p2]-1);

       end;

      { writeln(ss);
       for i:=1 to n do begin for j:=1 to n do if dd[i,j]<100 then write(dd[i,j]:2,' ') else write(' * '); writeln;   end;
       }

       writeln(dd[1,n]);

 1: close (output);
     end.

var d:array [0..501,0..501] of int64;
	i,j,n,l,r,k:longint;
    s:ansistring;

function min (a,b:int64):int64;
begin
	if (a <= b)
    	then min := a
        else min := b;
end;

function calc (l,r:longint):int64;
begin
	if (d[l][r] >= 0)
    then calc := d[l][r]
    else begin
    if (l > r) then calc := 0
    else begin
    if (l = r)
    then begin
    d[l][r] := 1;
    calc := 1;
    end
    else begin
    	//writeln ('Im in');
    	d[l][r] := calc(l+1,r) + 1;
        for i:=l+1 to r do
        	if (s[l] = s[i]) then
            d[l][r] := min (d[l][r], calc(l+1,i-1) + calc(i,r));
        calc := d[l][r];
    end;
    end;
    end;
end;

begin
	readln (n);
    readln (s);
    for i:=0 to n+1 do
    	for j:=0 to n+1 do
        	d[i][j] := -1;

    writeln (calc(1,n));
    (*
    for i:=1 to n do
    begin
    	for j:=1 to n do
         	write (d[i][j],' ');
    writeln();
    end;*)
end.

                      const eps=0.0000000001;  besk1=200000008;  nnn=4600000;
            besk=80000000000000000;
              modul=1000000007{998244353} ;

   label 22,1,2,3,4,33;
    type    real=extended;   double=extended;
    mas=array [-300000..nnn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3,p4 :int64;end; zap1=^zap;
    mass=array[-10000..nnn] of longint;mass1=^mass;
    matr=array[-10..200,-10..200] of int64;
    matr1=^matr;
    var oldpp,t,pos1,pos2,r,razm,kollad,leftx,rightx,lefty,righty,num,dirx,diry,oldii,obr,koludal,maxdl,mindl,tmin,aaa,bbb,ccc,kolst,kollek,aa,bb,t1,t2,kolx,koly,ans,ans1,ans2,dl,posleft,posright,n,xxx,yyy,dx,dy,m,w,h,jjj,l,cc,mnog,nn,t3,t4,t5,t6,posmax,tmax,kold,kk,j2,ttt,ppp,pmin,pmax,limit,posi,posj,diam,oldt,ot1,time,pos,ll,posx,posy,dloch,newdl,oldn,oldm,ost,ot,p1,p2,p3,p4,znamzz,kolperiod,znam,tperiod,start,finish,kol1,kol2,lavel,p0,jj,ii,ogr,q,p,pp,tt,oldtt,qq,qq1,qq2,q1,q2,imax,nm,smin,cen:int64;
   istart,jstart,ifinish,jfinish,k,i2,i3,step2,k1,k2,pp0,mask,i1,j1,step1, step, i,j:longint;
   zagr,xx,yy,kolizm,test,zz,predok,xold,yold,x1,x0,d,b,a,zsum,y,x,z:array[-200000..1535002] of int64;
    otmat,amat,bmat,cmat:matr;
   gr1,gr2,gr:array[-1..2000,-1..2000] of boolean;
    ddl,ddr:array[-1..5002,-1..5002] of longint;
    prob1,prob2,prob3,pr1new,pr2new,pr3new,pr1,pr2,pr3:zap;
    iii,oldpos,finot,vv,znak:int64;
    aold:mas;  anss:zap;
    sss,ss,ss1,ss2:string;
    newstr,str:array[-1000..200000] of string;
    lll,rrr,v,dist,alpha,phi:extended;
    masmatr:array[-1..101,-1..101,-1..101] of int64;
    zzz,ddnew,koef,polex,ddsum,dd:array[-1..4,-1..1300000] of int64;
    sum,kol,ppos,mma,ma:array[-1000..200005,-1..5] of int64;
    xleft,xright,xplus,xminus,px,py,xc,yc,xxc,yyc:extended;
    del:array[-1..100001,-1..20] of longint;
    z0,y1,z1,z2,kolnul,fact,next,prev,s,name,dnew, voltay,c,day:mas;
    zzzz:array[0..125000000] of byte;
    aaaa,bbbb,x2:extended;
    delit:array[0..100000,0..20] of longint;
    pole:array[-10..2002,-10..2005] of char;
    ddd,matrr,ppole,dd3,dd4:array[-10..2000,-10..2200] of int64;
    ddnnew:array[-1..12,-1..12,0..200,0..3] of int64;
   newzan,marked,zanx,zany:array[-1000000..2000000] of boolean;
    ssold,sss1,sss2:string;
    def,stepen,koled,och,newoch,place,newnabor,stoim,nabor:array[-10..500005] of int64;
     zanleft,zanright,zan,fl:array[-100000..10000000] of boolean;
     dost:array[-1..210,-1..210,0..3,0..3] of int64;
    sss12:string;ch,ch1,ch2:char;
    pr,hesh,numright,dr: array [-10..206,-1..16] of int64;
    s3,s2,s1:array[-100..500000] of string;

    grr :array [-10..2010,-10..2010] of extended;
    maxpr:array[0..nnn] of string;
     tx,ty,vel,ott,v0,v1,s0,t0:int64;
     zv:point;
     left,right,ugol,rot,temp,sumtemp,vol,newx,newy:array[-1000..400000] of int64;
     mash,sqx,sqy,ottt:extended;
     xxxx,yyyy,yot:double;
       flag2,flag,flag1:boolean;

  function max(a,b:int64):int64;
begin max:=a; if b>a then max:=b;   end;

  function min(a,b:int64):int64;
begin min:=a; if b<a then min:=b;   end;

procedure udal(p:longint);
begin  next[prev[p]]:=next[p]; prev[next[p]]:=prev[p]; end;

      function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

     function summ(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p2+xx.p2*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=t1 div tt mod modul;
    t2:=t2 div tt mod modul;
    ott.p1:=t1; ott.p2:=t2;

   summ:=@ott;
 end;

     function prod(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=(t1 div tt) mod modul;
    t2:=(t2 div tt) mod modul;
    ott.p1:=t1; ott.p2:=t2;

   prod:=@ott;
 end;

    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p{/pi*180};
 end;

function degg(a,k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k shr 1); degg:=p*p mod modul;   end;

end;

function prost(tt:int64):boolean;
var aa:extended; i,p,t:longint;  fl:boolean;
 begin
   fl:=true;
   aa:=tt;
   aa:=sqrt(aa);
   t:=round(aa);
   for i:=2 to t do if tt mod i=0 then fl:=false;

   prost:=fl;
 end;

function arcsin(pp:extended):extended;
var tt:extended;
begin
   if (abs(pp)<=1+eps)and (abs(pp)>=1-eps)
   then if pp>0 then arcsin:=pi/2 else arcsin:=-pi/2;
   tt:=1-pp*pp;
   if abs(tt)>=0 then
     begin
        arcsin:=arctan(pp/sqrt(tt));

     end;

end;

function gl(ch:char):boolean;
begin
 if (ch='o')or (ch='a')or(ch='e')or(ch='u')or(ch='i') then gl:=true else gl:=false;

end;

function zaprmin(left,right:longint):int64;
begin
   if left>=right then zaprmin:=y[left] else
     begin
        if not odd(left) and odd(right) then zaprmin:=zaprmin(left shr 1,right shr 1) else
         begin
          if odd(left) then zaprmin:=min(zaprmin(left+1,right),y[left]);
          if not odd(right) then zaprmin:=min(zaprmin(left,right-1),y[right]);

         end;

     end;

end;

 function ff(gr:int64):boolean;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=m;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<gr then aa:=cc else bb:=cc;

    end;
   writeln(' cc= ',cc);
   cc:=min(cc+3,m+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
  ff:=fl;
end;

function opt(ss:string):int64;
var t,i,j,k:longint; ot,p:int64;  sss:string;
begin
 if ss='' then opt:=0 else
    begin
      t:=0;
      k:=length(ss);
      for i:=1 to k do if ss[i]=ss[1] then
        begin inc(t); x[t]:=i;  end;
        if  ss[k+1]<>ss[1] then begin inc(t); x[t]:=k+1;  end;
       sss:='';
      for i:=1 to t-1 do sss:=sss+copy(ss,x[i]+1,x[i+1]-x[i]-1);
       writeln('sss=',sss);
    end;
    { j:=opt(sss); }
 opt:=j+1;
end;

begin
  {  assign (input,'D:\Projects\input.txt');reset(input);
      assign (output,'D:\Projects\output.txt'); rewrite(output);
   }
     readln(n);
     readln(ss);

     for step:=1 to n do
       begin
          t:=0;
          k:=length(ss);
           if k=0 then goto 2;
               for i:=1 to k do if ss[i]=ss[1] then
                begin inc(t); x[t]:=i;  end;
                 if  ss[k+1]<>ss[1] then begin inc(t); x[t]:=k+1;  end;
                 sss:='';
                for i:=1 to t-1 do sss:=sss+copy(ss,x[i]+1,x[i+1]-x[i]-1);
              { writeln('sss=',sss);   }
               ss:=sss;
       end;

    2:
         writeln(step-1);

1:             close(output);
end.

                                          const eps=1e-10;
      besk=8000000000000000000; label 1,3,2,44;
type mas=array[-10000..550000+1] of int64; integer=longint;
var len,i1,j1,mask,stepp,h,n2,i,j,k,l,step,k1,w,mesto,num:longint;
ss,ss1:string;
dx,dy,ll,rr,sum,m,start,finish,time,p3,p4,jj,qqq,ii,tt,pmax,pmax2,qq,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,n,nn,kk,modul,t0,t1,n1,t2,q,t,p:int64; flag1:boolean;
  summ,place,kol,str,a2,b2,left,right,zz,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
 jmax,maxx, gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
  marked,zan:array[-10..1000000] of boolean;
  a1,b1,strok:array[-10..550000] of int64;
  stroka:array[-1000..1000000] of char;
  ot1,otmax,v:extended;
  sp,sss:array[-10..2000000] of string;
  newpole,dd,pole:array[-100..1210,-1..1210] of int64;
  dchet,dnech,poschet,posnechet:array[-10..290000,-1..30] of int64;
  pos:int64;
  ch:char;
  flagg1:boolean;
  ymax,ymin,xmax,xmin,znach,z,nomer,newplace,newstr,s,next,prev,xx,yy,aold,x,y:array[-100000..2000002] of int64;
  ddd:array[-10..5010,-10..5010] of int64;
 function srav(i,j:longint):boolean;
  begin if (a[i]<a[j])or(a[i]=a[j])and(a1[i]<a1[j])or(a[i]=a[j])and(a1[i]=a1[j])and(a2[i]<a2[j])  then
  srav:=true else srav:=false; end;

procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
until (k>=n);

end;

function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

function phi(a,b:double):double; label 222;var p:double;
begin
  if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
  if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
  if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
  if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
  if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
  222: phi:=p;
end;

function nod(a,b:int64):int64; var p,t:int64;
begin
  a:=abs(a); b:=abs(b);
  if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
nod:=p;
end;

function nok(a,b:int64):int64;
begin  nok:=(a*b) div nod(a,b);  end;

   function degg(a:int64;k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
   begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

end;

procedure udal(ii:longint);
begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

function nomerr(gr:int64):int64;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=p;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<=gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,p+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
   { if fl then nomerr:=a1[cc] else nomerr:=-1000;}
   nomerr:=cc;
end;

 function vhodit(t:int64):boolean;
var sum,ii,jj,p:int64;  ans:boolean;
begin
   p:=t;
   for i:=1 to t do a[i]:=x[i];
    n:=1;
    repeat n:=n*2 until n>=p;
         for i:=p+1 to n+2 do a[i]:=besk;
        sort(a);
    { for i:=1 to p do write(a[i],' '); writeln;
     }
     sum:=0;
    if not odd(t) then
     for i:=1 to t div 2 do sum:=sum+a[2*i] else
     for i:=1 to (t+1) div 2 do sum:=sum+a[2*i-1];
    { writeln('sum= ',sum);
     }
 ans:=sum<=hh;
vhodit:=ans;
end;

function prost(pp:longint):boolean;
var i,j,t:longint; tt:extended; fl:boolean;
begin
  tt:=pp;
  tt:=sqrt(tt);
  fl:=true;
  for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

 prost:=fl;

end;

function check(t:int64):boolean;
var tmin,ll,rr,kol,tt,i,j,k:longint; flag,fl:boolean;
begin
   tmin:=0;
   for i:=1 to n do
     begin
        ll:=a[i];rr:=a[i]+t;
        if (tmin>=ll)and(tmin<=rr) then begin   end;

     end;

end;

begin

 {  assign (input,'D:\Projects\input.txt');reset(input);
   assign (output,'D:\Projects\output.txt'); rewrite(output);
  }

    readln(n);
    readln(ss);
    for i:=1 to n do for j:=1 to n do dd[i,j]:=besk;
    for i:=1 to n do dd[i,i]:=1;
    for len:=2 to n do for i:=1 to n-len+1 do
       begin
           p1:=i; p2:=i+len-1;
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2-1]+1);
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]);
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]);

           if ss[p1]=ss[p1+1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]);
           if ss[p2]=ss[p2-1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]+1);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]+1);

       end;

      { writeln(ss);
       for i:=1 to n do begin for j:=1 to n do if dd[i,j]<100 then write(dd[i,j]:2,' ') else write(' * '); writeln;   end;
       }

       writeln(dd[1,n]);

 1: close (output);
     end.

                                          const eps=1e-10;
      besk=8000000000000000000; label 1,3,2,44;
type mas=array[-10000..550000+1] of int64; integer=longint;
var len,i1,j1,mask,stepp,h,n2,i,j,k,l,step,k1,w,mesto,num:longint;
ss,ss1:string;
dx,dy,ll,rr,sum,m,start,finish,time,p3,p4,jj,qqq,ii,tt,pmax,pmax2,qq,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,n,nn,kk,modul,t0,t1,n1,t2,q,t,p:int64; flag1:boolean;
  summ,place,kol,str,a2,b2,left,right,zz,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
 jmax,maxx, gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
  marked,zan:array[-10..1000000] of boolean;
  a1,b1,strok:array[-10..550000] of int64;
  stroka:array[-1000..1000000] of char;
  ot1,otmax,v:extended;
  sp,sss:array[-10..2000000] of string;
  newpole,dd,pole:array[-100..1210,-1..1210] of int64;
  dchet,dnech,poschet,posnechet:array[-10..290000,-1..30] of int64;
  pos:int64;
  ch:char;
  flagg1:boolean;
  ymax,ymin,xmax,xmin,znach,z,nomer,newplace,newstr,s,next,prev,xx,yy,aold,x,y:array[-100000..2000002] of int64;
  ddd:array[-10..5010,-10..5010] of int64;
 function srav(i,j:longint):boolean;
  begin if (a[i]<a[j])or(a[i]=a[j])and(a1[i]<a1[j])or(a[i]=a[j])and(a1[i]=a1[j])and(a2[i]<a2[j])  then
  srav:=true else srav:=false; end;

procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
until (k>=n);

end;

function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

function phi(a,b:double):double; label 222;var p:double;
begin
  if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
  if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
  if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
  if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
  if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
  222: phi:=p;
end;

function nod(a,b:int64):int64; var p,t:int64;
begin
  a:=abs(a); b:=abs(b);
  if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
nod:=p;
end;

function nok(a,b:int64):int64;
begin  nok:=(a*b) div nod(a,b);  end;

   function degg(a:int64;k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
   begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

end;

procedure udal(ii:longint);
begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

function nomerr(gr:int64):int64;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=p;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<=gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,p+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
   { if fl then nomerr:=a1[cc] else nomerr:=-1000;}
   nomerr:=cc;
end;

 function vhodit(t:int64):boolean;
var sum,ii,jj,p:int64;  ans:boolean;
begin
   p:=t;
   for i:=1 to t do a[i]:=x[i];
    n:=1;
    repeat n:=n*2 until n>=p;
         for i:=p+1 to n+2 do a[i]:=besk;
        sort(a);
    { for i:=1 to p do write(a[i],' '); writeln;
     }
     sum:=0;
    if not odd(t) then
     for i:=1 to t div 2 do sum:=sum+a[2*i] else
     for i:=1 to (t+1) div 2 do sum:=sum+a[2*i-1];
    { writeln('sum= ',sum);
     }
 ans:=sum<=hh;
vhodit:=ans;
end;

function prost(pp:longint):boolean;
var i,j,t:longint; tt:extended; fl:boolean;
begin
  tt:=pp;
  tt:=sqrt(tt);
  fl:=true;
  for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

 prost:=fl;

end;

function check(t:int64):boolean;
var tmin,ll,rr,kol,tt,i,j,k:longint; flag,fl:boolean;
begin
   tmin:=0;
   for i:=1 to n do
     begin
        ll:=a[i];rr:=a[i]+t;
        if (tmin>=ll)and(tmin<=rr) then begin   end;

     end;

end;

begin

  { assign (input,'D:\Projects\input.txt');reset(input);
   assign (output,'D:\Projects\output.txt'); rewrite(output);
   }

    readln(n);
    readln(ss);
    for i:=1 to n do for j:=1 to n do dd[i,j]:=besk;
    for i:=1 to n do dd[i,i]:=1;
    for len:=2 to n do for i:=1 to n-len+1 do
       begin
           p1:=i; p2:=i+len-1;
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2-1]+1);
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]);
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]);

           if ss[p1]=ss[p1+1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]);
           if ss[p2]=ss[p2-1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]+1);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]+1);
           for j:=p1+1 to p2-1 do if (ss[p1]=ss[j])and(ss[j]=ss[p2]){and(dd[p1,j]>1)or(dd[j,p2]>1)} then
            dd[p1,p2]:=min(dd[p1,p2],dd[p1,j]+dd[j,p2]-1);

       end;

      { writeln(ss);
       for i:=1 to n do begin for j:=1 to n do if dd[i,j]<100 then write(dd[i,j]:2,' ') else write(' * '); writeln;   end;
       }

       writeln(dd[1,n]);

 1: close (output);
     end.

                                          const eps=1e-10;
      besk=8000000000000000000; label 1,3,2,44;
type mas=array[-10000..550000+1] of int64; integer=longint;
var len,i1,j1,mask,stepp,h,n2,i,j,k,l,step,k1,w,mesto,num:longint;
ss,ss1:string;
dx,dy,ll,rr,sum,m,start,finish,time,p3,p4,jj,qqq,ii,tt,pmax,pmax2,qq,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,n,nn,kk,modul,t0,t1,n1,t2,q,t,p:int64; flag1:boolean;
  summ,place,kol,str,a2,b2,left,right,zz,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
 jmax,maxx, gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
  marked,zan:array[-10..1000000] of boolean;
  a1,b1,strok:array[-10..550000] of int64;
  stroka:array[-1000..1000000] of char;
  ot1,otmax,v:extended;
  sp,sss:array[-10..2000000] of string;
  newpole,dd,pole:array[-100..1210,-1..1210] of int64;
  dchet,dnech,poschet,posnechet:array[-10..290000,-1..30] of int64;
  pos:int64;
  ch:char;
  flagg1:boolean;
  ymax,ymin,xmax,xmin,znach,z,nomer,newplace,newstr,s,next,prev,xx,yy,aold,x,y:array[-100000..2000002] of int64;
  ddd:array[-10..5010,-10..5010] of int64;
 function srav(i,j:longint):boolean;
  begin if (a[i]<a[j])or(a[i]=a[j])and(a1[i]<a1[j])or(a[i]=a[j])and(a1[i]=a1[j])and(a2[i]<a2[j])  then
  srav:=true else srav:=false; end;

procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
until (k>=n);

end;

function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

function phi(a,b:double):double; label 222;var p:double;
begin
  if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
  if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
  if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
  if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
  if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
  222: phi:=p;
end;

function nod(a,b:int64):int64; var p,t:int64;
begin
  a:=abs(a); b:=abs(b);
  if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
nod:=p;
end;

function nok(a,b:int64):int64;
begin  nok:=(a*b) div nod(a,b);  end;

   function degg(a:int64;k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
   begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

end;

procedure udal(ii:longint);
begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

function nomerr(gr:int64):int64;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=p;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<=gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,p+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
   { if fl then nomerr:=a1[cc] else nomerr:=-1000;}
   nomerr:=cc;
end;

 function vhodit(t:int64):boolean;
var sum,ii,jj,p:int64;  ans:boolean;
begin
   p:=t;
   for i:=1 to t do a[i]:=x[i];
    n:=1;
    repeat n:=n*2 until n>=p;
         for i:=p+1 to n+2 do a[i]:=besk;
        sort(a);
    { for i:=1 to p do write(a[i],' '); writeln;
     }
     sum:=0;
    if not odd(t) then
     for i:=1 to t div 2 do sum:=sum+a[2*i] else
     for i:=1 to (t+1) div 2 do sum:=sum+a[2*i-1];
    { writeln('sum= ',sum);
     }
 ans:=sum<=hh;
vhodit:=ans;
end;

function prost(pp:longint):boolean;
var i,j,t:longint; tt:extended; fl:boolean;
begin
  tt:=pp;
  tt:=sqrt(tt);
  fl:=true;
  for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

 prost:=fl;

end;

function check(t:int64):boolean;
var tmin,ll,rr,kol,tt,i,j,k:longint; flag,fl:boolean;
begin
   tmin:=0;
   for i:=1 to n do
     begin
        ll:=a[i];rr:=a[i]+t;
        if (tmin>=ll)and(tmin<=rr) then begin   end;

     end;

end;

begin

  { assign (input,'D:\Projects\input.txt');reset(input);
   assign (output,'D:\Projects\output.txt'); rewrite(output);
   }

    readln(n);
    readln(ss);
    for i:=1 to n do for j:=1 to n do dd[i,j]:=besk;
    for i:=1 to n do dd[i,i]:=1;
    for len:=2 to n do for i:=1 to n-len+1 do
       begin
           p1:=i; p2:=i+len-1;
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2-1]+1);
           if ss[p1]=ss[p1+1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]);
           if ss[p2]=ss[p2-1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]+1);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]+1);

       end;

      { writeln(ss);
       for i:=1 to n do begin for j:=1 to n do if dd[i,j]<100 then write(dd[i,j]:2,' ') else write('  * '); writeln;   end;
       }

       writeln(dd[1,n]);

 1: close (output);
     end.

                                          const eps=1e-10;
      besk=8000000000000000000; label 1,3,2,44;
type mas=array[-10000..550000+1] of int64; integer=longint;
var len,i1,j1,mask,stepp,h,n2,i,j,k,l,step,k1,w,mesto,num:longint;
ss,ss1:string;
dx,dy,ll,rr,sum,m,start,finish,time,p3,p4,jj,qqq,ii,tt,pmax,pmax2,qq,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,n,nn,kk,modul,t0,t1,n1,t2,q,t,p:int64; flag1:boolean;
  summ,place,kol,str,a2,b2,left,right,zz,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
 jmax,maxx, gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
  marked,zan:array[-10..1000000] of boolean;
  a1,b1,strok:array[-10..550000] of int64;
  stroka:array[-1000..1000000] of char;
  ot1,otmax,v:extended;
  sp,sss:array[-10..2000000] of string;
  newpole,dd,pole:array[-100..1210,-1..1210] of int64;
  dchet,dnech,poschet,posnechet:array[-10..290000,-1..30] of int64;
  pos:int64;
  ch:char;
  flagg1:boolean;
  ymax,ymin,xmax,xmin,znach,z,nomer,newplace,newstr,s,next,prev,xx,yy,aold,x,y:array[-100000..2000002] of int64;
  ddd:array[-10..5010,-10..5010] of int64;
 function srav(i,j:longint):boolean;
  begin if (a[i]<a[j])or(a[i]=a[j])and(a1[i]<a1[j])or(a[i]=a[j])and(a1[i]=a1[j])and(a2[i]<a2[j])  then
  srav:=true else srav:=false; end;

procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
begin
i:=l;j:=m; flag:=true; step:=0;while flag do begin
if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
inc(step);inc(i);
{writeln('step=',step,' i=',i);} end;
if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
inc(step);inc(j);end;
if  ((i>=l+k) or (j>=m+k)) then flag:=false;
end;
if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
end;
procedure sort(var c:mas);

begin

k:=1; repeat
l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
until (k>=n);

end;

function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

function phi(a,b:double):double; label 222;var p:double;
begin
  if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
  if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
  if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
  if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
  if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
  222: phi:=p;
end;

function nod(a,b:int64):int64; var p,t:int64;
begin
  a:=abs(a); b:=abs(b);
  if (a>0)and(b>0) then
   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
    p:=a;
   end else if a=0 then p:=b else p:=a;
nod:=p;
end;

function nok(a,b:int64):int64;
begin  nok:=(a*b) div nod(a,b);  end;

   function degg(a:int64;k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
   begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

end;

procedure udal(ii:longint);
begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

function nomerr(gr:int64):int64;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=p;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<=gr then aa:=cc else bb:=cc;

    end;
  { writeln(' cc= ',cc);
  } cc:=min(cc+3,p+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
   { if fl then nomerr:=a1[cc] else nomerr:=-1000;}
   nomerr:=cc;
end;

 function vhodit(t:int64):boolean;
var sum,ii,jj,p:int64;  ans:boolean;
begin
   p:=t;
   for i:=1 to t do a[i]:=x[i];
    n:=1;
    repeat n:=n*2 until n>=p;
         for i:=p+1 to n+2 do a[i]:=besk;
        sort(a);
    { for i:=1 to p do write(a[i],' '); writeln;
     }
     sum:=0;
    if not odd(t) then
     for i:=1 to t div 2 do sum:=sum+a[2*i] else
     for i:=1 to (t+1) div 2 do sum:=sum+a[2*i-1];
    { writeln('sum= ',sum);
     }
 ans:=sum<=hh;
vhodit:=ans;
end;

function prost(pp:longint):boolean;
var i,j,t:longint; tt:extended; fl:boolean;
begin
  tt:=pp;
  tt:=sqrt(tt);
  fl:=true;
  for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

 prost:=fl;

end;

function check(t:int64):boolean;
var tmin,ll,rr,kol,tt,i,j,k:longint; flag,fl:boolean;
begin
   tmin:=0;
   for i:=1 to n do
     begin
        ll:=a[i];rr:=a[i]+t;
        if (tmin>=ll)and(tmin<=rr) then begin   end;

     end;

end;

begin

  { assign (input,'D:\Projects\input.txt');reset(input);
   assign (output,'D:\Projects\output.txt'); rewrite(output);
   }

    readln(n);
    readln(ss);
    for i:=1 to n do for j:=1 to n do dd[i,j]:=besk;
    for i:=1 to n do dd[i,i]:=1;
    for len:=2 to n do for i:=1 to n-len+1 do
       begin
           p1:=i; p2:=i+len-1;
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2-1]+1);
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]);
           if ss[p1]=ss[p2] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]);

           if ss[p1]=ss[p1+1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]);
           if ss[p2]=ss[p2-1] then  dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1+1,p2]+1);
           dd[p1,p2]:=min(dd[p1,p2],dd[p1,p2-1]+1);
           for j:=p1+1 to p2-1 do if (ss[p1]=ss[j])and(ss[j]=ss[p2])and(dd[p1,j]>1)and(dd[j,p2]>1) then
            dd[p1,p2]:=min(dd[p1,p2],dd[p1,j]+dd[j,p2]-1);

       end;

      { writeln(ss);
       for i:=1 to n do begin for j:=1 to n do if dd[i,j]<100 then write(dd[i,j]:2,' ') else write(' * '); writeln;   end;
       }

       writeln(dd[1,n]);

 1: close (output);
     end.


var n:longint;s:ansistring;
procedure Input;
begin
 readln(n);
 readln(s);
end;
procedure Work;
var i,j,k:longint;
begin
 j:=0;
 k:=0;
 for i:=1 to n do
  if s[i]='1' then inc(k);
 if k*2<>n then begin writeln(1); write(s); readln; halt; end;
 for i:=1 to n do
  begin
   if s[i]='1' then inc(j);
   if (j*2<>i) and ((k-j)*2<>n-i) then
    begin
     writeln(2);
     write(copy(s,1,i),' ',copy(s,i+1,n-i));
     readln;
     halt;
    end;
  end;
end;
begin
 Input;
 Work;
end.

function hor(const s:string):boolean;
var n, e, i: longint;
begin
 n:= 0;
 e:= 0;
 for i:= 1 to length(s) do begin
     if (s[i]='0') then
         inc(n);
     if (s[i]='1') then
         inc(e);
 end;
 if (e<>n) then
     hor:= true
 else hor:= false;
end;

var s: string;
n, i:longint;
g: boolean;
begin
 readln(n);
 readln(s);
 if hor(s) then begin
     writeln(1);
     writeln(s);
 end else begin
     g:= false;
     for i:= 1 to n do
         if not g and hor(copy(s, 1, i)) and hor(copy(s, i+1, length(s))) then begin
             g:= true;
             writeln(2);
             writeln(copy(s, 1, i), ' ', copy(s, i+1, length(s)));
         end;
 end;
end.

program ppp;

var n,l,n0,n1: integer;
    s, s_out: string;
//    a,b,k:array of int64;
    n_out: integer;

begin

 readln(n);
 readln(s);
 for var i:=1 to n do begin
  if s[i]='0' then n0:=n0+1
   else n1:=n1+1;
  if n0<>n1 then begin
    s_out:=s;
    n_out:=1;
   end
  else begin
    n_out:=2;
    s_out:= s[1]+ ' ' + RightStr(s,n-1);
   end;

 end;

 writeln(n_out);
 writeln(s_out);
end.

var
n,t,x,i,k:int64;
a:string;
begin
  readln(t);
  read(a);
  for i:=1 to t do
    if a[i]='1' then k:=k+1 else x:=x+1;
  if k=x then begin writeln(2); write(a[1],' ',copy(a,2,t-1));end else begin
    writeln(1); write(a); end;

end.

var
	b, n, c, m, x, x1, x2: integer;
	s: string;
	a, a1: array of integer;

begin

	readln(c);
	readln(s);
	for var i := 1 to s.length do
	begin
		if (s[i] = '0') then
		begin
			x += 1;
		end
		else x1 += 1;
	end;
	if (x = x1) then
	begin
		writeln(2);
		write(s[1], ' ');
		delete(s, 1, 1);
		writeln(s);
	end
	else begin
		writeln(1);
		writeln(s);
	end;

end.

var n,i,k:longint;
    s,s1:string;
BEGIN
readln(n);
readln(s);

k:=0;
for i:=1 to n do
 begin
 if s[i] = '1' then
  inc(k);
 end;

if (n-k > k) or (n-k < k)  then
begin
writeln(1);
writeln(s);
end
else
begin
s1:=copy(s,1,s.Length-1);
writeln(2);
writeln(s1,' ',s[n]);
end;
END.

var
  n, i, x1, x2: integer;
  s: string;

begin
  readln(n);
  readln(s);

  if n=1 then
  begin
  writeln('1');
  writeln(s);
  end
  else
begin

  for i := 1 to n do
    if s[i] = '1' then x1 := x1 + 1
    else
      x2 := x2 + 1;

  if x1 = x2 then
  begin
    writeln('2');
    write(s[1]);
    write(' ');
    for i := 2 to n do
      write(s[i]);
  end
  else
  begin
  writeln('1');
  writeln(s);
  end;
end;
end.

var
s:string;
len, num0, num1, i :integer;
begin
readln(len);
readln(s);
num0:=0;
num1:=0;
for i:=1 to length(s) do begin
if s[i] = '1' then
num1:=num1 + 1
else
num0 := num0 + 1;
end;
if num1 <> num0 then begin
writeln(1);
for i := 1 to length(s) do
write(s[i]);
end
else begin
writeln(2);
write(s[1],' ');
for i:=2 to length(s) do
write(s[i]);
end;
end.

var s:string;
t,cnt1,n,cnt2:integer;
begin
  readln(n);

    read(s);
    cnt1:=0;
    cnt2:=0;
     n:=length(s);
     for var j:=1 to n do begin
        if s[j]='1' then cnt1:=cnt1+1
        else cnt2:=cnt2+1;
     end;
     if cnt1<>cnt2 then writeln(1,' ',s)
     else  begin
        writeln(2);
        write(copy(s,1,n-1),' ',s[n]);
     end

end.

Var
    n, n0, n1: Int64;
    s: String;

Begin
    Readln(n);
    Readln(s);
    For Var i := 1 to n do
        If S[i] = '1' then
            n1 += 1
        Else
            n0 += 1;
    If n1 <> n0 then Begin
        Writeln(1);
        Write(s)
    End
    Else Begin
        Writeln(2);
        Write(S[1], ' ');
        Delete(S, 1, 1);
        Write(S)
    End
End.

Program ILoveYou;
VAR n,i,nr1,nr2:int64; s:string;
Begin

Readln(n);
Readln(s);
for i:=1 to length(s) do
Begin
if (s[i] = '1') then nr1:=nr1 + 1 else nr2:=nr2 + 1;
end;

if (nr1 <> nr2) then
Begin

Writeln(1);
Writeln(s);

end else
Begin

Writeln(2);
Write(s[1],' ');
for i:=2 to length(s) do
Begin
Write(s[i]);
end;

end;

Readln;
END.

var
  n,k0,k1:byte;
  s:string;
  c:char;
begin
  readln(n);
  s:='';
  for var i:=1 to n do
    begin
      read(c);
      case c of
        '1':inc(k1);
        '0':inc(k0);
      end;
      s:=s+c;
    end;
  if k0=k1 then
    begin
      writeln(2);
      writeln(s[1]);
      Delete(s,1,1);
      writeln(s);
    end
  else
    begin
      writeln(1);
      writeln(s);
    end;
end.

                                                 const eps=1e-10;
          besk=4000000000000000000; label 1,3,2,44;
    type mas=array[-10000..5500000+1] of int64; integer=longint;
    var p0,i2,i3,dl,len,i1,j1,mask,stepp,h,n2,i,j,k,l,step,k1,mesto,num:longint;
    ss,ss1,ss2:string;
    koll,w,pos,dx,dy,ll,rr,sum,m,start,finish,time,p3,p4,jj,qqq,ii,tt,pmax,pmax2,qq,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,n,nn,kk,modul,t0,t1,n1,t2,q,t,p:int64; flag1:boolean;
      summ,place,kol,str,a2,b2,left,right,zz,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
     shag,posx,posy,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
      prost,marked,zan:array[-10..4000000] of boolean;
      predok,a1,b1,strok:array[-10..550000] of int64;
      stroka:array[-1000..1000000] of char;
      ot1,otmax,v:extended;
      zzz:array[0..100,0..100] of longint;
      sp,sss:array[-10..2000000] of string;
      newpole,pole:array[-1..1100,-1..700] of char;
      dd,ddinv,dnech,poschet,posnechet:array[-10..390000,-1..25] of int64;
      poss:int64;
      ch:char;
      flagg1:boolean;
      s,ymax,ymin,xmax,xmin,znach,z,nomer,newplace,newstr,next,prev,xx,yy,aold,x,y:array[-100000..4000002] of int64;
      ddd:array[-10..5010,-10..5010] of int64;
     function srav(i,j:longint):boolean;
      begin if (a[i]<a[j])or(a[i]=a[j])and(a1[i]<a1[j])or(a[i]=a[j])and(a1[i]=a1[j])and(a2[i]<a2[j])  then
      srav:=true else srav:=false; end;

    procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
    begin
    i:=l;j:=m; flag:=true; step:=0;while flag do begin
    if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
    inc(step);inc(i);
    {writeln('step=',step,' i=',i);} end;
    if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
    inc(step);inc(j);end;
    if  ((i>=l+k) or (j>=m+k)) then flag:=false;
    end;
    if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
    if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
    end;
    procedure sort(var c:mas);

    begin

    k:=1; repeat
    l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
    for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
    until (k>=n);

    end;

    function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
    function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;

    function phi(a,b:double):double; label 222;var p:double;
    begin
      if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
      if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
      if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
      if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
      if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
      222: phi:=p;
    end;

    function nod(a,b:int64):int64; var p,t:int64;
    begin
      a:=abs(a); b:=abs(b);
      if (a>0)and(b>0) then
       begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
        p:=a;
       end else if a=0 then p:=b else p:=a;
    nod:=p;
    end;

    function nok(a,b:int64):int64;
    begin  nok:=(a*b) div nod(a,b);  end;

       function degg(a:int64;k:int64):int64; var p:int64;
    begin
     if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
       begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

    end;

    procedure udal(ii:longint);
    begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

    function nomerr(gr:int64):int64;

    var ot,aa,bb,cc:int64; fl:boolean;
    begin
      aa:=1; bb:=p;  cc:=aa; fl:=false;
      while abs(aa-bb)>1 do
        begin
           cc:=(aa+bb) shr 1;
         {  writeln('cc=++ ',cc);
         }  if y[cc]<gr then aa:=cc else bb:=cc;

        end;
      { writeln(' cc= ',cc);
      } cc:=max(cc-3,0);
       repeat inc(cc) until y[cc]>=gr;
       if y[cc]=gr then fl:=true else fl:=false;
       { if fl then nomerr:=a1[cc] else nomerr:=-1000;}
       nomerr:=cc;
    end;

    function pprost(pp:longint):boolean;
    var i,j,t:longint; tt:extended; fl:boolean;
    begin
      tt:=pp;
      tt:=sqrt(tt);
      fl:=true;
      for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

     pprost:=fl;

    end;

    function gl(c:char):boolean;
    begin
     if (c='a')or (c='o')or(c='e')or(c='i')or(c='u') then gl:=true else gl:=false;

    end;

    function goodstr(pos:int64):boolean;
    var i,j:longint; fl:boolean;
    begin
      fl:=true;
      for i:=0 to 25 do if dd[pos,i]<x[i] then fl:=false;

    goodstr:=fl;
    end;

    begin

    {   assign (input,'D:\Projects\input.txt');reset(input);
       assign (output,'D:\Projects\output.txt'); rewrite(output);
     }
       readln(p);
       readln(ss);
        for i:=1 to p do
          begin
            if ss[i]='1' then inc(p1) else inc(p0);

          end;
          if p0=p1 then
            begin
              writeln(2);
              write(ss[1],' ');
              for i:=2 to p do write(ss[i]);

            end else
            begin
              writeln(1);
              writeln(ss);

            end;

     1: close (output);
         end.

var
  s : string;
  i,j,n,m,k : longint;
begin
  readln(n);
  readln(s);
  for i := 1 to n do
    if (s[i] = '1') then
      inc(m)
    else
      inc(k);
  if (m = k) then
  begin
    writeln(2);
    for i := 1 to length(s)-1 do
      write(s[i]);
    write(' ',s[n]);
  end
  else
  begin
    writeln(1);
    writeln(s);
  end;
end.

program a;

{$APPTYPE CONSOLE}

   uses Math;
   var  b:array[1..100] of longint;
        i,n,z,k,kilk,k1,k2:longint;
        c:char;
        s,s1:string;
begin
   readln(n);
   readln(s);
   if n=1 then
      begin
          writeln(1);
          writeln(s)
      end else if n=2 then
         begin
             if s[1]=s[2] then
                begin
                   writeln(1);
                   writeln(s)
                end else
                  begin
                      writeln(2);
                      writeln(s[1],' ',s[2])
                  end
         end else if n>2 then
            begin
               if n mod 2=1 then
                  begin
                     writeln(1);
                     writeln(s)
                  end else if n mod 2=0  then
                     begin
                        kilk:=0;
                        for i:=1 to n do
                            if s[i]='0' then inc(kilk);
                        if kilk<>n-kilk then
                            begin
                               writeln(1);
                               writeln(s)
                            end else
                               begin
                                  k1:=0;
                                  k2:=0;
                                  c:=s[1];
                                  if c='1' then
                                      begin
                                         writeln(2);
                                         write(c,' ');
                                         delete(s,1,1);
                                         writeln(s)
                                      end else
                                         begin
                                            k2:=1;
                                            for i:=2 to n do
                                               begin
                                                   if s[i]='1' then inc(k1) else inc(k2);
                                                   if (k1<>k2) and (k1>0) then
                                                       begin
                                                          s1:=copy(s,1,i);
                                                          delete(s,1,i);
                                                          break
                                                       end
                                               end;
                                            writeln(2);
                                            writeln(s1,' ',s)
                                         end
                               end
                     end
            end;  readln
end.

Program KeanuReeves;
var s,s1,s2:string; n,i,t1,t2,k1,k2:byte;
begin   //assign(input,'1189A.inp'); reset(input);
        //assign(output,'1189A.out'); rewrite(output);
        readln(n);
        readln(s);
        t1:=0; t2:=0;
        for i:=1 to length(s) do
        if s[i]='1' then t1:=t1+1
        else t2:=t2+1;
        if t1<>t2 then
        begin   writeln(1); writeln(s); exit;
        end else
        begin   k1:=0; k2:=0;
                for i:=1 to length(s) do
                begin   if s[i]='1' then k1:=k1+1
                        else k2:=k2+1;
                        if (k1<>k2) and (t1-k1<>t2-k2) then
                        begin   s1:=copy(s,1,i); s2:=copy(s,i+1,length(s)-i+1);
                                writeln(2); write(s1,#32,s2);
                                exit;
                        end;
                end;
        end;
        //close(input); close(output);
end.

const fi='';
      fo='';
var f:text;
    n,i,so0,so1,s:longint;
    st,kq:ansistring;

begin
  assign(f,fi);reset(f);
  readln(f,n);
  read(f,st);

  assign(f,fo);rewrite(f);
  for i:=1 to n do
        if st[i]='0' then inc(so0) else inc(so1);
  if so1 <> so0 then begin writeln(f,1); writeln(f,st) end
  else
  begin
  for i:=1 to (n div 2) do
        begin
          if st[i]='0' then
          begin
            kq:=kq+'0';
            dec(so0);
          end;
          if st[i]='1' then
          begin
            kq:=kq+'1';
            dec(so1);
          end;
          if so1 <> so0 then begin s:=i; break; end;
        end;
  writeln(f,2);
  write(f,kq,' ');
  for i:=s+1 to n do
        write(f,st[i]);
  end;
  close(f);
end.

var S:STRING; c0,c1,n,i:integer;

begin
readln(n);
readln(s);
c0:=0;
c1:=0;
for i:=1 to n do begin
if (s[i]='1') then begin
inc(c1);
end
else
begin
inc(c0);
end;
end;
if c1=c0 then begin
writeln(2);
for i:=1 to n-1 do begin
write(s[i]);
end;
writeln(' ',s[n]);
end
else
begin
writeln(1);
writeln(s);
end;
end.

var n,i,j,k:longint;
s,a,b:ansistring;
function gud(s:ansistring):boolean;
var i,r,c:longint;
tf:boolean;
begin
r:=0; c:=0;
tf:=true;
for i:=1 to length(s) do if s[i]='1' then inc(r) else inc(c);
if r=c then tf:=false;
gud:=tf;
end;
begin
readln(n);
readln(s);
if gud(s) then begin writeln('1'); writeln(s); end else
begin
a:='';
 for i:=1 to length(s) do
  begin
   for j:=1 to i do a:=a+s[j];
   if gud(a) then
    begin
     b:='';
     for k:=i+1 to length(s) do b:=b+s[k];
     if gud(b) then
      begin
       writeln('2');
       writeln(a,' ',b);
       break;
      end;
    end;
  end;
end;
readln;
end.

var
    n,i,x:longint;
    s:string;
begin
    readln(n); readln(s);
    for i:=1 to n do
        if s[i]='1' then inc(x);
    if x<<1=n then
    begin
        writeln(2);
        writeln(copy(s,1,n-1),' ',s[n]);
    end
    else
    begin
        writeln(1);
        writeln(s);
    end;
end.

var
    n,i,x:longint;
    s:string;
begin
    readln(n); readln(s);
    for i:=1 to n do x:=x+ord(s[i])-48;
    if x*2=n then
    begin
        writeln(2);
        writeln(copy(s,1,n-1),' ',s[n]);
    end
    else
    begin
        writeln(1);
        writeln(s);
    end;
end.

var
x,y,x1,y1,x2,y2,z,q, i,j,k,k1,m,h1,t,n,bx,by:longint;
a,a1,a0,b,c:longint;
s:ansistring;
flag:boolean;

//1000000000000000000
//1000000000000000000
begin
    //You're breathtaking!
    readln(n);
    readln(s);
    a0:=0;
    a1:=0;
    for i:=1 to n do begin
        if (s[i]='0') then a0:=a0+1
        else a1:=a1+1;
    end;
    if (a0<>a1) then begin
        writeln(1);
        writeln(s);
    end
    else begin
        writeln(2);
        for i:=1 to n-1 do
            write(s[i]);
        write(' ',s[n]);
    end;
end.

var
n,i,zero,one:longint;
s:string;
begin
readln(n);
readln(s);

for i:=1 to n do begin
    if s[i]='0' then inc(zero)
    else
    inc(one);
end;
    if one<>zero then begin
        writeln(1);
        writeln(s);
    end
    else begin
          writeln(2);
          for i:=1 to length(s)-1 do write(s[i]);
          write(' ');
          write(s[n]);
          writeln;
    end;
end.

//type ansistring = string;

function is_good (n:longint; s:ansistring):boolean;
var i,one,zero:longint;
begin
    one:=0;
    zero:=0;
    for i:= 1 to n do begin
        if s[i] = '1' then
            inc(one)
        else
            inc(zero)
    end;
    is_good:= one <> zero
end;

var
    n:longint;
    s:ansistring;

begin
    readln(n);
    readln(s);
    if is_good(n,s) then begin
        writeln(1);
        writeln(s);
    end else begin
        writeln(2);
        writeln(copy(s,1,length(s)-1),' ',s[length(s)]);
    end;
end.

var s:string;
    n,i,tot:longint;
begin
  readln(n);readln(s);
  for i:=1 to length(s) do if s[i]='1' then inc(tot);
  if (tot<>length(s) div 2) or ((n and 1)>0) then begin writeln(1);writeln(s);exit;end;
  writeln(2);write(s[1],' ');delete(s,1,1);writeln(s);
end.

var n,i:word;
    st:string;
    s0,s1:array [0..100] of word;

begin
  //Assign(input,'KR.inp');   reset(input);
  //Assign(output,'KR.out');   rewrite(output);
  readln(n);   read(st);
  for i:=1 to n do
    if (st[i]='0') then
      begin
        s0[i]:=s0[i-1]+1;   s1[i]:=s1[i-1];
      end
    else begin
        s1[i]:=s1[i-1]+1;   s0[i]:=s0[i-1];
      end;
  if (s0[n]<>s1[n]) then
    begin
      writeln(1);   write(st);
    end
  else for i:=1 to n-1 do
    if (s0[i]<>s1[i]) and (s0[n]-s0[i]<>s1[n]-s1[i]) then
      begin
        writeln(2);
        write(copy(st,1,i),#32,copy(st,i+1,n-i));
        break;
      end;
end.

var n,count0,count1,i:longint;
    s:string;
begin
        readln(n);
        read(s);
        for i:=1 to length(s) do
        begin
                if s[i]='0' then inc(count0)
                else inc(count1);
        end;
        if count0<>count1 then
        begin
                writeln(1);
                writeln(s);
        end
        else
        begin
                writeln(2);
                for i:=1 to length(s)-1 do write(s[i]);
                write(' ');
                write(s[length(s)]);
        end;
end.

program aaaaaaaaaaaa;
var
s:string;
a,b:array[0..1000] of longint;
n,i,k,o,tmp:longint;
begin

        readln(n);
        readln(s);
        for i:=1 to n do
        begin

        a[i]:=a[i]+a[i-1]+ord(s[i])-48;
        end;
        o:=0;
        k:=0;

        repeat
                tmp:=o;
                for i:=o+1 to n do if (a[i]-a[tmp]<>i-tmp-(a[i]-a[tmp])) then o:=i;
                b[o]:=1;
                inc(K);
        until o=n;
        writeln;
        writeln(k);
        for i:=1 to n do
        begin
        write(s[i]);
        if (b[i]=1) and (i<>n) then write(' ');
        end;

end.

var s : string;
    i,k0,k1,l : longint;
begin
   readln(l);
   readln(s);
   for i:=1 to length(s) do
      begin
      if s[i]='0' then inc(k0);
      if s[i]='1' then inc(k1);
      end;
   if k0=k1 then
      begin
      writeln(2);
      for i:=1 to length(s)-1 do
         write(s[i]);
      write(' ',s[length(s)]);
      end
   else
   begin
   writeln(1);
   writeln(s);
   end;
end.

var s:string;
    i,n,k1,k2:longint;
begin
  readln(n);
  readln(s);
  for i:=1 to n do if s[i]='0' then inc(k1) else dec(k1);
  if k1<>0 then begin writeln(1); writeln(s); end
  else begin writeln(2);writeln(s[1],' ',copy(s,2,n-1)); end
end.

var
n,a,b,i:longint;
s:string;
begin
readln(n);
readln(s);
a:=0;
b:=0;
for i:=1 to n do
  if s[i]='0' then inc(a)
              else inc(b);
if a=b then
  begin
    writeln('2');
    writeln(s[1],' ',copy(s,2,n-1));
  end
  else
    begin
      writeln('1');
      writeln(s);
    end;
end.

var n,c0,c1,i:longint;
    a:ansistring;
begin
  readln(n);
  readln(a);
  for i:=1 to length(a) do
    if a[i]='1' then
      inc(c1)
    else
      inc(c0);
  if c1<>c0 then writeln(1,#13,a)
  else writeln(2,#13,a[1],' ',copy(a,2,length(a)-1));
end.

var
    n,i,x:longint;
    s,t:string;
begin
    readln(n); readln(s);
    if n=1 then
    begin
        writeln(n);
        writeln(s);
        exit;
    end;
    for i:=1 to n do
        if s[i]='1' then inc(x);
    if x*2=n then
    begin
        writeln(2);
        t:=copy(s,1,n-1);
        writeln(t,' ',s[n]);
    end
    else
    begin
        writeln(1);
        writeln(s);
    end;
end.

var
x,y,x1,y1,x2,y2,z,q, i,j,k,k1,m,h1,t,n,bx,by:longint;
a,a1,a0,b,c:longint;
s:ansistring;
flag:boolean;

//1000000000000000000
//1000000000000000000
begin
    //You're breathtaking!
    readln(n);
    readln(s);
    a0:=0;
    a1:=0;
    for i:=1 to n do begin
        if (s[i]='0') then a0:=a0+1
        else a1:=a1+1;
    end;
    if (a0<>a1) then begin
        writeln(1);
        writeln(s);
    end
    else begin
        writeln(2);
        for i:=1 to n-1 do
            write(s[i]);
        write(s[n]);
    end;
end.

//type ansistring = string;

function is_good (n:longint; s:ansistring):boolean;
var i,one,zero:longint;
begin
    one:=0;
    zero:=0;
    for i:= 1 to n do begin
        if s[i] = '1' then
            inc(one)
        else
            inc(zero)
    end;
    is_good:= one <> zero
end;

var
    n:longint;
    s:ansistring;

begin
    readln(n);
    readln(s);
    if is_good(n,s) then begin
        writeln(n);
        writeln(s);
    end else begin
        writeln(2);
        writeln(copy(s,1,length(s)-1),' ',s[length(s)]);
    end;
end.

var s:string;
    n,i,tot:longint;
begin
  readln(n);readln(s);
  for i:=1 to length(s) do if s[i]='1' then inc(tot);
  if tot<>length(s) div 2 then begin writeln(s);exit;end;
  write(s[1],' ');delete(s,1,1);writeln(s);
end.

var s:string;
    n,i,tot:longint;
begin
  readln(n);readln(s);
  for i:=1 to length(s) do if s[i]='1' then inc(tot);
  if tot<>length(s) div 2 then begin writeln(1);writeln(s);exit;end;
  writeln(2);write(s[1],' ');delete(s,1,1);writeln(s);
end.

var n,c0,c1,i:longint;
    a:ansistring;
begin
  readln(n);
  readln(a);
  for i:=length(a) downto 1 do
    if a[1]='1' then
      inc(c1)
    else
      inc(c0);
  if c1<>c0 then writeln(1,#13,a)
  else writeln(2,#13,a[1],#13,copy(a,2,length(a)-1));
end.

var
    n:longint;
    s,t:string;
begin
    readln(n); readln(s);
    if n=1 then
    begin
        writeln(n);
        writeln(s);
        exit;
    end;
    t:=copy(s,1,n-1);
    writeln(t,' ',s[n]);
end.

var
    n:longint;
    s,t:string;
begin
    readln(n); readln(s);
    if n=1 then
    begin
        writeln(n);
        writeln(s);
        exit;
    end;
    t:=copy(s,1,n-1);
    writeln(2);
    writeln(t,' ',s[n]);
end.

var
	b, n, c, m, x, x1, x2: integer;
	s: string;
	a, a1: array of integer;

begin

	readln(c);
	readln(s);
	for var i := 1 to c do
	begin
		if (s[i] = '0') then
		begin
			x += 1;
		end
		else x1 += 1;
	end;
	if (x = x1) then
	begin
		writeln(2);
		for var i := 1 to s.length do
		begin
			write(s[i]);
			if (i = s.length - 1) then write(' ');
		end;
	end
	else begin
		writeln(c);
		for var i := 1 to s.length do
		begin
			write(s[i]);
			if (i = s.length div 2) then write(' ');
		end;
	end;

end.

var
  n, i, x1, x2: integer;
  s: string;

begin
  readln(n);
  readln(s);

  if n=1 then
  begin
  writeln('1');
  writeln(s);
  end;

  for i := 1 to n do
    if s[i] = '1' then x1 := x1 + 1
    else
      x2 := x2 + 1;

  if x1 = x2 then
  begin
    writeln('2');
    write(s[1]);
    write(' ');
    for i := 2 to n do
      write(s[i]);
  end;

end.

var
s:string;
len, num0, num1, i :integer;
begin
readln(len);
readln(s);
for i:=1 to length(s) do begin
if s[i] = '1' then
num1:=num1 + 1
else
num0 := num0 + 1;
end;
if num1 <> num0 then begin
writeln(1);
for i := 1 to length(s) do
writeln(s[i]);
end
else begin
writeln(2);
write(s[1],' ');
for i:=2 to length(s) do
write(s[i]);
end;
end.

program a;

{$APPTYPE CONSOLE}

   uses Math;
   var  b:array[1..100] of longint;
        i,n,z,k,kilk,k1,k2:longint;
        c:char;
        s,s1:string;
begin
   readln(n);
   readln(s);
   if n=1 then
      begin
          writeln(1);
          writeln(s)
      end else if n=2 then
         begin
             if s[1]=s[2] then
                begin
                   writeln(1);
                   writeln(s)
                end else
                  begin
                      writeln(2);
                      writeln(s[1],' ',s[2])
                  end
         end else if n>2 then
            begin
               if n mod 2=1 then
                  begin
                     writeln(1);
                     writeln(s)
                  end else if n mod 2=0  then
                     begin
                        kilk:=0;
                        for i:=1 to n do
                            if s[i]='0' then inc(kilk);
                        if kilk<>n-kilk then
                            begin
                               writeln(1);
                               writeln(s)
                            end else
                               begin
                                  k1:=0;
                                  k2:=0;
                                  c:=s[1];
                                  if c='1' then
                                      begin
                                         writeln(2);
                                         write(c,' ');
                                         delete(s,1,1);
                                         writeln(s)
                                      end else
                                         begin
                                            for i:=2 to n do
                                               begin
                                                   if s[i]='1' then inc(k1) else inc(k2);
                                                   if (k1<>k2) and (k1>0) then
                                                       begin
                                                          s1:=copy(s,1,i);
                                                          delete(s,1,i);
                                                          break
                                                       end
                                               end;
                                            writeln(2);
                                            writeln(s1,' ',s)
                                         end
                               end
                     end
            end;
end.

program a;

{$APPTYPE CONSOLE}

   uses Math;
   var  b:array[1..100] of longint;
        i,n,z,k,kilk,k1,k2:longint;
        s,s1:string;
begin
   readln(n);
   readln(s);
   if n=1 then
      begin
          writeln(1);
          writeln(s)
      end else if n=2 then
         begin
             if s[1]=s[2] then
                begin
                   writeln(1);
                   writeln(s)
                end else
                  begin
                      writeln(2);
                      writeln(s[1],' ',s[2])
                  end
         end else if n>2 then
            begin
               kilk:=0;
               for i:=1 to n do
                  if s[i]='0' then inc(kilk);
               if kilk<>n-kilk then
                  begin
                     writeln(1);
                     writeln(s)
                  end else if kilk=n-kilk then
                     begin
                        if s[1]='1' then
                            begin
                               writeln(2);
                               write(s[1],' ');
                               delete(s,1,1);
                               writeln(s)
                            end else if s[1]='0' then
                               begin
                                  k1:=1;
                                  k2:=0;
                                  for i:=2 to n do
                                     begin
                                        if s[i]='0' then inc(k1) else inc(k2);
                                        if (k1<>k2) and (k2>0) then
                                           begin
                                              s1:=copy(s,1,i);
                                              delete(s,1,i);
                                              break
                                           end
                                     end;
                                  writeln(s1,' ',s)
                               end
                     end
            end;
end.