var s:string;
    ans:longint;

procedure openfile;
  begin
    assign(input,'a.in'); reset(input);
    assign(output,'a.out'); rewrite(output);
  end;

procedure endfile;
  begin
    close(input); close(output);
  end;

procedure dfs(x,now:longint;y:string);
  var plus,tmp:longint;
      t:string;
  begin
    if length(y)=0 then exit;
    if x=3 then begin
      if length(y)>7 then exit;
      if (length(y)>1)and(y[1]='0') then exit;
      val(y,plus,tmp);
      if plus>1000000 then exit;
      now:=now+plus;
      if now>ans then ans:=now;
      exit;
    end;
    t:='';
    while (length(t)<=7)and(length(y)>0) do begin
      t:=t+y[1];
      delete(y,1,1);
      if (length(t)>1)and(t[1]='0') then exit;
      val(t,plus,tmp);
      if plus<=1000000 then dfs(x+1,now+plus,y);
    end;
  end;

begin
  //openfile;
  ans:=-1;
  readln(s);
  dfs(1,0,s);
  writeln(ans);
  //endfile;
end.

var
        s:string;
        i,j,k,ans,k1,k2,k3:longint;
begin

readln(s);
ans:=-1;
for i:=2 to length(s)-1 do
for j:=i+1 to length(s) do
        begin
        if (i-1>=8)or((s[1]='0')and(i>2)) then continue;
        if (j-i>=8)or((s[i]='0')and(j-i>=2)) then continue;
        if (length(s)-j+1>=8)or((s[j]='0')and(length(s)-j+1>=2)) then continue;
        k1:=0;
        for k:=1 to i-1 do k1:=k1*10+ord(s[k])-ord('0');
        k2:=0;
        for k:=i to j-1 do k2:=k2*10+ord(s[k])-ord('0');
        k3:=0;
        for k:=j to length(s) do k3:=k3*10+ord(s[k])-ord('0');
        if (k1<=1000000)and(k2<=1000000)and(k3<=1000000) then
        if (ans<k1+k2+k3) then ans:=k1+k2+k3;
        end;
writeln(ans);

end.

Uses Math, SysUtils;
Const c='1000000';
Var i,j,l:LongInt;
s,s1,s2,s3:String;
k,max:LongInt;
Begin
     //Assign (input,'input.txt'); ReSet (input);
     //Assign (output,'output.txt'); ReWrite (output);
     Readln (s);
     If s='000' then Begin Writeln (0);Exit End;
     l:=Length (s);
     max:=0;
     For I:=1 to l do
     Begin
          For J:=i+1 to l-1 do
          Begin
               s1:=Copy (s,1,i);
               s2:=Copy (s,i+1,j-i);
               s3:=Copy (s,j+1,l-(j-i+1));
               If ((s1[1]<>'0') or (Length (s1)=1)) and ((s2[1]<>'0') or (Length (s2)=1)) and ((s3[1]<>'0') or (Length (s3)=1)) and
                  ((Length (s1)<7)or (s1=c)) and ((Length (s2)<7) or (s2=c)) and ((Length (s3)<7) or (s3=c))
               then Begin

                         k:=StrToInt (s1)+StrToInt (s2)+StrToInt (s3);
                         If k>max
                         then max:=k;
                    End;
          End;
     End;
     If max=0
     then Writeln (-1)
     else Writeln (max);
End.

{$MACRO ON}
{$define W:=write}
{$define Wln:=Writeln}
{$define R:=read}
{$define Rln:=Readln}
{$define Wh:=while}
{$define arr:=array}
{$define str:=string}
{$define Int:=Integer}
{$define Long:=LongInt}
{$define Ansi:=AnsiString}
{$define Bool:=Boolean}
{$define func:=function}
{$define proc:=procedure}
{$define be:=begin}
{$define en:=end}
{$define el:=else}
{$define brk:=break}
{$define th:=then}

uses Classes, SysUtils, StrUtils, Math;

var
	s, ca, cb, cc: AnsiString;
  a, b, c: Long;
  L, sa, sb, sc: Int64;
	M: Int64;

begin
	Rln(s);
  L := Length(s);
  if l < 3 th
  be
  	Wln(-1);
    exit;
  en;
  if s = '000' th
  be
  	Wln(0);
    exit;
  en;
  {if s[1] = '0' th
  be
  	Wln(-1);
    exit;
  en;}
  M := -1;
  for a := 1 to Min(7, L - 2) do
  be
  	ca := Copy(s, 1, a);
    if ca <> '0' th
	    if ca[1] = '0' th
  	  	brk;
    sa := StrToInt(ca);
    if a = 7 th
    	if sa > 1000000 th
        brk;
  	for b := a + 1 to Min(a + 7, L - 1) do
    be
    	cb := Copy(s, a + 1, b - (a + 1) + 1);
    	if cb <> '0' th
      	if cb[1] = '0' th
        	brk;
      sb := StrToInt(cb);
      if Length(cb) = 7 th
        if sb > 1000000 th
    			brk;
      //
      	cc := Copy(s, b + 1, l);
        //W(a, ' ', b, ': ');
        //Wln(ca, ' ', cb, ' ', cc);
        if cc <> '0' th
      		if cc[1] = '0' th
            continue;
        if Length(cc) > 7 th
        	continue;
        sc := StrToInt(cc);
        if Length(cc) = 7 th
          if sc > 1000000 th
            continue;
        M := Max(M, sa + sb + sc);
    en;
	en;
  Wln(M);
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var s:string;
    a,b,m:integer;
    h,j,k:integer;

procedure finish;
begin
  write(-1);
  halt
end;

function max(x,y:integer):integer;
begin
  if x>y then max:=x else max:=y;
end;

begin
  read(s);
  m:=-1;

  if length(s)<3 then finish else
  for a:=1 to length(s)-2 do
    for b:=a+1 to length(s)-1 do
    begin
      if (s[1]='0')and(a>1) then continue;
      if (s[a+1]='0')and(b>a+1) then continue;
      if (s[b+1]='0')and(b<>length(s)-1) then continue;

      if length(copy(s,1,a))>7 then continue;
      if length(copy(s,a+1,b-a))>7 then continue;
      if length(copy(s,b+1,length(s)-b))>7 then continue;

      h:=strtoint(copy(s,1,a));
      j:=strtoint(copy(s,a+1,b-a));
      k:=strtoint(copy(s,b+1,length(s)-b));
      if (h<=1000000)and(j<=1000000)and(k<=1000000) then
      m:=max(m,h+j+k);
    end;

  write(m);
end.

{$R-,S-,Q-,I-,O+}
var
  s: ansistring;
  i,j,k,v,q,n: longint;
  f: array [0..333,0..4] of longint;
begin
  readln(s);
  n:=length(s);
  for i:=0 to n do
    for j:=0 to 3 do f[i,j]:=-1000000000;
  f[0,0]:=0;
  for i:=1 to n do
    for j:=1 to 3 do
      for k:=i-8 to i do
      begin
        if k < 1 then continue;
        if (k < i) and (s[k] = '0') then continue;
        v:=0;
        for q:=k to i do v:=v*10+Ord(s[q])-48;
        if v > 1000000 then continue;
        if f[k-1,j-1]+v > f[i,j] then f[i,j]:=f[k-1,j-1]+v;
      end;
  if f[n,3] < 0 then writeln('-1')
  else writeln(f[n,3]);
end.

program  tachchuoi;
var
    s,z:string;
    i,j,l,n:integer;
    res,u,v,y:int64;
function tinh(t:string):int64;
var  k,a,err:integer;temp,x:int64;
begin
    if((t[1]='0')and(length(t)>1) ) then exit(-1);
    x:=1;
  //  writeln(t);
    temp:=0;
    for k:=length(t) downto 1 do
         begin
            val(t[k],a,err);
            temp:=temp+a*x;
            if(temp>1000000)then exit(-1);
            x:=x*10;
         end;
//    writeln(temp);
    exit(temp);
end;
begin
   readln(s);
   n:=length(s);
   res:=-1;
      for j:=2 to n-2+1 do
         for l:=j+1 to n do
           begin
               z:=copy(s,1,j-1);
               u:=tinh(z);
               z:=copy(s,j,l-j);
               v:=tinh(z);
               z:=copy(s,l,n-l+1);
               y:=tinh(z);
               if((u<>-1)and(v<>-1)and(y<>-1))then
                   if(res<u+v+y) then res:=u+v+y
               else  continue;
           end;
   writeln(res);
end.

var i,j,max,n,x1,x2,x3:longint;
    s,s1,s2,s3:string;
 begin
  readln(s);
  n:=length(s);
  max:=-1;
  for i:=1 to n-2 do
   for j:=i+1 to n-1 do
    begin
     s1:=copy(s,1,i);
     s2:=copy(s,i+1,j-i);
     s3:=copy(s,j+1,n-j);

     if (length(s1)<=7) and
        (length(s2)<=7) and
        (length(s3)<=7) then begin
                              val(s1,x1);
                              val(s2,x2);
                              val(s3,x3);

                              if ((s1[1]='0') and (length(s1)>1)) or
                                 ((s2[1]='0') and (length(s2)>1)) or
                                 ((s3[1]='0') and (length(s3)>1)) then continue;

                              if (x1<=1000000) and
                                 (x2<=1000000) and
                                 (x3<=1000000) then begin
                                                     if x1+x2+x3>max then max:=x1+x2+x3;
                                                    end;
                             end;
    end;
  writeln(max);
 end.

const   maxn=500;
        inf=1000000001;
        finp='';
        fout='';
var     fi,fo:text;
        s:string;
        f:array[0..maxn,0..5]of longint;
procedure enter;
begin
        assign(fi,finp);reset(fi);
                readln(fi,s);
        close(fi);
end;
procedure solve;
var     i,j,k,v,q,n:longint;
begin
        assign(fo,fout);rewrite(fo);
                n:=length(s);
                for i:=0 to n do
                        for j:=0 to 3 do
                                f[i,j]:=-inf;
                f[0,0]:=0;
                for i:=1 to n do
                        for j:=1 to 3 do
                                for k:=i-8 to i do
                                begin
                                        if k < 1 then continue;
                                        if (k < i) and (s[k]='0') then continue;
                                        v:=0;
                                        for q:=k to i do
                                                v:=v*10 + ord(s[q])-48;
                                        if v > 1000000 then continue;
                                        if f[k-1,j-1] + v > f[i,j] then
                                                f[i,j]:=f[k-1,j-1]+v;
                                end;
                if f[n,3] < 0 then writeln(fo,-1)
                else writeln(fo,f[n,3]);
        close(fo);
end;
begin
        enter;
        solve;
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  i,j,n,m,k,g,ans,z,x,y:integer;
  s:string;

begin
  readln(s);
  n:=length(s);
  ans:=-1;

  for i:=1 to n-2 do
  begin
    for j:=i+1 to n-1 do
    begin
      if (s[1]='0') then
        x:=0
      else if (i>8) then
        break
      else
        x:=strtoint(copy(s,1,i));
      if (s[1]='0') and (i>1) then
        break;
      if (s[i+1]='0') then
        y:=0
      else if (j-i>8) then
        break
      else
        y:=strtoint(copy(s,i+1,j-i));
      //writeln(i,' ',j,' ',j-i,' ',y);
      if (s[i+1]='0') and (j<>i+1) then
        break;
      if (s[j+1]='0') then
        z:=0
      else if (n-j>8) then
        continue
      else
        z:=strtoint(copy(s,j+1,n-j));
      if (s[j+1]='0') and (j+1<>n) then
        continue;
      if (x>1000000) or (y>1000000) or (z>1000000) then
        continue;
      if (x+y+z>ans) then
        ans:=x+y+z;
    end;
  end;

  write(ans);

  readln;
  readln;
end.

{$APPTYPE CONSOLE}
uses
  SysUtils;
var
 s:string;
 i,j,n,c,k,q,g,w:longint;
 sum1,sum2,sum3:int64;
 sum:int64;
 mas:array[1..30] of longint;
 B,v,breakall:BOOLEAN;
begin
 readln(S);
 n:=length(s);
i:=0;
b:=true;
sum1:=0;
sum2:=0;
sum3:=0;
sum:=0;
b:=false;
breakall:=false;
if (length(s)<3) then writeln('-1') else begin
 repeat
     inc(i);
     c:=ord(s[i])-48;
     if not (s[i] in ['0'..'9'] )then break;
     if (i=2) and (sum1=0)  then begin
         break;
     end;
    sum1:=sum1*10+c;
    if (sum1>1000000) then break;
    j:=i;
    sum2:=0;

    repeat
       inc(j);
       v:=false;
       q:=ord(s[j])-48;
         if not (s[j]  in ['0'..'9']) then begin
           breakall:=true;
           break;
         end;
       if (j=i+2) and (sum2=0) then break;
       sum2:=sum2*10+q;
       if (sum2>1000000) then break;
       sum3:=0;
       for g:=j+1 to n do begin
           w:=ord(s[g])-48;
           if not (s[g] in['0'..'9']) then begin
           breakall:=true;
           break;
         end;
           if (g=j+2) and (sum3=0) then begin
           v:=true;
           break;
           end;
           sum3:=sum3*10+w;
           if (sum3>1000000) then begin
             v:=true;
             break;
           end;
       end;
    if (breakall) then break;
     if (v=false) then begin
        b:=true;
        if (sum1+sum2+sum3>sum) then sum:=sum1+sum2+sum3;
     end;

    until(j=n-1);
    if breakall then break;
 until(i=n-2);
if (b=true) then writeln(sum) else writeln('-1');
end;
end.

var
 a:array[1..100] of longint;
 n,i,j,k,t,s,max:longint;
 c:char;
begin
 n:=0;
 while not eoln do begin
  inc(n);
  read(c);
  a[n]:=ord(c)-ord('0');
 end;
 if n<3 then begin
  writeln(-1);
  halt;
 end;
 max:=-1;
 for i:=1 to n-2 do
  for j:=i+1 to n-1 do begin
   if i-2>7 then
    continue;
   if j-i>7 then
    continue;
   if n-j>7 then
    continue;
   s:=0;
   if (i>1) and (a[1]=0) then
    continue;
   if (j>i+1) and (a[i+1]=0) then
    continue;
   if (j<n-1) and (a[j+1]=0) then
    continue;
   t:=0;
   for k:=1 to i do
    t:=t*10+a[k];
   if t>1000000 then
    continue;
   s:=s+t;
   t:=0;
   for k:=i+1 to j do
    t:=t*10+a[k];
   if t>1000000 then
    continue;
   s:=s+t;
   t:=0;
   for k:=j+1 to n do
    t:=t*10+a[k];
   if t>1000000 then
    continue;
   s:=s+t;
   if s>max then
    max:=s;
  end;
 writeln(max);
end.

program pa;
var
	s:string;
	a:array[0..101] of longint;
	n,i1,i2,i3,i,j,k,ans,t:longint;

function max(x,y:longint):longint;
begin
	if x>y then exit(x) else exit(y);
end;

function check(x,y,z:longint):boolean;
var
	t:longint;
begin
	t:=1;
	if (a[t]=0)and(x<>1) then exit(false);
	if (x=7)and(copy(s,1,x)<>'1000000') then exit(false);
	t:=x+1;
	if (a[t]=0)and(y<>1) then exit(false);
	if (y=7)and(copy(s,x+1,y)<>'1000000') then exit(false);
	t:=x+y+1;
	if (a[t]=0)and(z<>1) then exit(false);
	if (z=7)and(copy(s,x+y+1,z)<>'1000000') then exit(false);
	check:=true;
end;

function work(x,y:longint):longint;
var
	i,t:longint;
begin
	t:=0;
	for i:=x to y do t:=t*10+a[i];
	exit(t);
end;

begin
	readln(s);
	if length(s)>21 then begin writeln('-1');halt;end;
	for i:=1 to length(s) do a[i]:=ord(s[i])-ord('0');
	ans:=-1;
	for i1:=1 to 7 do
		for i2:=1 to 7 do
			for i3:=1 to 7 do
				if (i1+i2+i3=length(s))and(check(i1,i2,i3)) then
					ans:=max(ans,work(1,i1)+work(i1+1,i2+i1)+work(i1+i2+1,i3+i2+i1));
	writeln(ans);
end.

program Task1;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

var s,s1,s2,s3: string;
    i,j,k,sum,st: integer;

function may(s: string): boolean;
var t: integer;
begin
  if (s[1]='0')then begin
    if (length(s)=1)then
      may:=true
    else
      may:=false;
    exit;
  end;
  if (length(s)>7)then begin
    may:=false;
    exit;
  end;
  t:=strtoint(s);
  if (t>1000000)then begin
    may:=false;
    exit;
  end;
  st:=st+t;
  may:=true;
end;

begin
  read(s);
  sum:=-1;
  for i:=1 to length(s)-2 do
    for j:=i+1 to length(s)-1 do begin
      s1:=copy(s,1,i);
      s2:=copy(s,i+1,j-i);
      s3:=copy(s,j+1,length(s)-j);
      st:=0;
      if (may(s1)and
          may(s2)and
          may(s3))then
            sum:=max(sum,st);
    end;
  write(sum);
end.

program prog;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Math;

var s, sa, sb, sc : string;
 i1, i2 : integer;
 ans, t : integer;

function f (s :string) : boolean;
var n : integer;
begin
  result := false;
  if s = '0' then exit;
  result := (s[1] = '0') or ((length(s) > 7)) or (strtoint(s) > 1000000)
end;

begin
//  reset (input, 'input.txt');
//  rewrite (output, 'output.txt');
  readln(s);
  ans := -1;
  for i1 := 2 to length(s)-1 do begin
  for i2 := i1+1 to length(s) do begin
    sa := copy(s, 1, i1-1);
    sb := copy(s, i1, i2-i1);
    sc := copy(s, i2, length(s)-i2+1);
    if f(sa) or f(sb) or f(sc) then continue;
    t := strtoint(sa) + strtoint(sb) + strtoint(sc);
    if t > ans then ans := t;
  end;
  end;
  write(ans);
//  close (input);
//  close (output);
end.

var
A,b,i,a1,b1,c1,max:longint;
S:string;
Procedure chit;
Var
I:longint;
Begin
A1:=0;
B1:=0;
C1:=0;
If (a>1) and (s[1]='0') then
Begin
A1:=maxlongint;
Exit;
End;
For i:=1 to a do
A1:=a1*10+ord(s[i])-ord('0');
If (a+1<b)  and (s[a+1]='0') then
Begin
B1:=maxlongint;
Exit;
End;
For i:=a+1 to b do
B1:=b1*10+ord(s[i])-ord('0');
If (length(s)>b+1) and (s[b+1]='0')  then
Begin
C1:=maxlongint;
Exit;
End;
For i:=b+1 to length(s) do
C1:=c1*10+ord(s[i])-ord('0');
End;
Function check1(a:longint):boolean;
Begin
If (a<length(s)) and (a>0) then exit(true);
Exit(false);
End;
Begin
Max:=-1;
Readln(s);
For i:=100 to 10000 do
Begin
A:=i div 100;
B:=i mod 100;
A1:=-1;
B1:=-1;
C1:=-1;
If (check1(a)) and (check1(b))  and (a<b) and (a-1<8) and (b-a<8) and (length(s)-b<8) then
Chit;
If (a1<1000001) and (b1<1000001) and (c1<1000001) then
If max<a1+b1+c1 then
Begin
//Writeln(a1,' ',b1,' ',c1);
//Writeln(a,' ',b);
max:=a1+b1+c1;
End;
End;
Write(max);
End.

program ta;
const
  maxn=1000000;
var
  s:string;
  n,i,j,a,b,c,d,x,y,z,max:longint;
  code:integer;
begin
  max:=-1;
  readln(s);
  n:=length(s);
  for i:=1 to n-2 do
  for j:=i+1 to n-1 do
  begin
    a:=i;b:=j-i;c:=n-j;
    if a<=7 then
    if b<=7 then
    if c<=7 then
    if (s[1]<>'0')or(a=1) then
    if (s[i+1]<>'0')or(b=1) then
    if (s[j+1]<>'0')or(c=1) then
    begin
      val(copy(s,1,a),x,code);
      val(copy(s,i+1,b),y,code);
      val(copy(s,j+1,c),z,code);
      if (x<=maxn) and (y<=maxn) and (z<=maxn) then
      begin
        d:=x+y+z;
        if d>max then max:=d;
      end;
    end;
  end;
  if max=-1 then writeln(-1)
  else writeln(max);
end.

var i,j,n,x1,x2,x3,max:longint; s,s1,s2,s3:string; p:integer;
 begin
  readln (s);
  n:=length(s);
  max:=-1;
  for i:=1 to n-1 do
   for j:=i+1 to n do
    begin
     s1:=copy(s,1,i);
     s2:=copy(s,i+1,j-i);
     s3:=copy(s,j+1,n-j);
     if (s1='') or (s2='') or (s3='') then continue
                                      else begin
     if ((length(s1)>1) and (s1[1]='0')) or
        ((length(s2)>1) and (s2[1]='0')) or
        ((length(s3)>1) and (s3[1]='0')) then continue
                                         else
        begin
         if (length(s1)>7) or (length(s2)>7) or
            (length(s3)>7) then continue
                           else begin
                                 val (s1,x1,p);
                                 val (s2,x2,p);
                                 val (s3,x3,p);
                                 if (x1<=1000000) and
                                    (x2<=1000000) and
                                    (x3<=1000000) and
                                    (x1+x2+x3>max) then max:=x1+x2+x3;
                                end;
        end;
                                           end;
    end;
  writeln (max);
 end.

const
        fi='';
        fo='';
var
        s,s1,s2,s3:string;
        i,j,max:longint;

procedure doc;
begin
        assign(input,fi);
        reset(input);
        read(s);
        close(input);
end;

procedure tinh2;
var     a,b,c,code,dk:longint;
begin
        s2:=copy(s,i+1,j);  dk:=0;
        if (s2<>'1000000') and (length(s2)>=7) then exit;
        if (s2[1]='0') and (s2<>'0') then exit;
        if length(s)-i-j+dk>7 then exit
        else if length(s)-i-j+dk=7 then
                begin
                        s3:=copy(s,i+j+1,7);
                        if (s3<>'1000000') and (length(s3)>=7) then exit;
                end
        else s3:=copy(s,i+j-dk+1,length(s)-i-j+dk);
        if (s3[1]='0') and (s3<>'0') then exit;
        val(s1,a,code); val(s2,b,code); val(s3,c,code);
        if a+b+c> max then max:=a+b+c;
end;

procedure tinh;
begin
        s1:=copy(s,1,i);
        if (i=7) and (s1<>'1000000') then exit;
        if (s1[1]='0') and (s1<>'0') then exit;
        for j:=1 to length(s)-i-1 do
                begin
                        if j>7 then exit;
                        tinh2;
                end;
end;

procedure xuly;
begin
        for i:=1 to length(s)-2 do
                begin
                        if i>7 then exit;
                        tinh;
                end;
end;

procedure ghi;
begin
        assign(output,fo);
        rewrite(output);
        if max<0 then write(-1) else write(max);
        close(output);
end;

begin
        doc;
        max:=-MaxLongint;
        xuly;
        ghi;
end.

Var sum,xx,yy,zz:int64;
    g,i,j:longint;
    s,x,y,z:string;
Begin
        Readln(s);
        sum:=-1;
        for i:=1 to length(s)-2 do
         for j:=i+1 to length(s)-1 do
         begin
                x:=copy(s,1,i);
                y:=copy(s,i+1,j-i);
                z:=copy(s,j+1,length(s)-j);
                if((x[1]='0')and(length(x)<>1))
                or((y[1]='0')and(length(y)<>1))
                or((z[1]='0')and(length(z)<>1))
                or(length(x)>7)
                or(length(y)>7)
                or(length(z)>7)
                then continue;
                val(x,xx,g);
                val(y,yy,g);
                val(z,zz,g);
                if(xx+yy+zz>sum)
                and(xx<=1000000)
                and(yy<=1000000)
                and(zz<=1000000)
                then sum:=xx+yy+zz;
         end;
        writeln(sum);
End.

var
    i,j,l,x,ans:longint;
    s:string;

function calca(l:longint; r:longint):longint;
var
    i,p:longint;
begin
    if (r>l)and(ord(s[l])=48) then exit(-100000000);
    p:=0;
    for i:=l to r do
    begin
        p:=p*10+ord(s[i])-48;
        if p>1000000 then exit(-100000000);
    end;
    exit(p);
end;

begin
    readln(s); l:=length(s);
    ans:=-1;
    for i:=1 to l-2 do
    for j:=i+1 to l-1 do
    begin
        x:=calca(1,i)+calca(i+1,j)+calca(j+1,l);
        if x>ans then ans:=x;
    end;
    writeln(ans);
end.

program problem1;
uses math;

var arr: array[1..21] of byte;

function numb( l, r: longWord ): longInt;
var i, a, res: longWord;
begin
  a := 1;
  res := 0;
  for i := r downTo l do
  begin
    res := res + ( arr[i] * a );
    a := a * 10;
  end;

  if ( res > 1000000 ) or ( ( arr[l] = 0 ) and ( r > l ) ) then
    numb := -1
  else
    numb := res;
end;

var chr: string[1];
    dp: array[ 1..21, 1..3 ] of longInt;
    i, j, k, cnt: longWord;
    m, c: longInt;

begin
  cnt := 0;

  read( chr );  while ( chr <> '' ) do
  while ( chr <> '' ) do
  begin
    inc( cnt );
    if ( cnt > 21 ) then
    begin
      writeln( '-1' );
      halt;
    end;

    arr[cnt] := ord( chr[1] ) - ord( '0' );

    read( chr );
  end;

  if ( cnt < 3 ) then
  begin
    writeln( '-1' );
    halt;
  end;

  for i := 1 to min( 7, (cnt-2) ) do
    dp[i][1] := numb( 1, i );

  for i := 2 to 3 do
  begin
    for j := i to min( (7*i), (cnt-3+i) ) do
    begin
      m := -1;
      for k := max( (i-1), (j-7) ) to min( 7*(i-1), (j-1) ) do
      begin
        c := numb( (k+1), j );
        if ( c > -1 ) and ( dp[k][i-1] > -1 ) and ( ( c + dp[k][i-1] ) > m ) then
          m := c + dp[k][i-1];
      end;
      dp[j][i] := m;
    end;
  end;

  writeln( dp[cnt][3] );
end.

program main;
type
 integer=longint;
var
 s:string;
 max:integer;
 procedure Input;
 begin
  readln(s);
 end;
 procedure Solve;
 var
  i,j,l:integer;
  s1,s2,s3,ss1,ss2,ss3:string;
  t1,t2,t3:integer;
  code:integer;
 begin
  max:=-1;
  l:=length(s);
  for i:=1 to l-2 do
    for j:=1 to l-i-1 do
    begin
      s1:=copy(s,1,i);
      s2:=copy(s,i+1,j);
      s3:=copy(s,i+j+1,l-i-j);
      if (length(s1)>8)or(length(s2)>8)
      or(length(s3)>8) then continue;
      val(s1,t1,code);
      val(s2,t2,code);
      val(s3,t3,code);
      if (t1>1000000)or(t2>1000000)or(t3>1000000) then
      continue;
      str(t1,ss1);
      if ss1<>s1 then continue;
      str(t2,ss2);
      if ss2<>s2 then continue;
      str(t3,ss3);
      if ss3<>s3 then continue;
      if t1+t2+t3>max then max:=t1+t2+t3;
    end;
 end;
 procedure Output;
 begin
  writeln(max);
 end;
begin
 Input;
 Solve;
 Output;
end.

var s,a,b,c:string;
    res,x,y,z,i,j:longint;
    p:integer;

 begin
   readln(s);
   res:=-1;
   for i:=1 to length(s)-2 do
    for j:=i+1 to length(s)-1 do
     begin
       a:=copy(s,1,i);
       b:=copy(s,i+1,j-i);
       c:=copy(s,j+1,length(s)-j);
       if length(a)>7 then continue;
       if length(b)>7 then continue;
       if length(c)>7 then continue;
       if (a[1] = '0')and(length(a)>1) then continue;
       if (b[1] = '0')and(length(b)>1) then continue;
       if (c[1] = '0')and(length(c)>1) then continue;

       val(a,x,p);
       val(b,y,p);
       val(c,z,p);
       if x>1000000 then continue;
       if y>1000000 then continue;
       if z>1000000 then continue;

       if (x+y+z>res) then res:=x+y+z;
     end;
    writeln(res);

 end.

var
  f :boolean;
  s,y,h,e :string;
  ans,x,r,z : int64;
  i,d,j,g,uu :  longint;
  code :integer;
begin
  readln(S);
  ans:=-1;
  d:=lengtH(s);
  i:=1;
  while (i<=d-1) do
  begin
  j:=i+1;
  while (j<= d) do
    begin
    y:='';
    f:=true;
    for uu:=1 to i do y:=y+s[uu];
    if ((y[1]='0') and (lengtH(y)>1)) or (length(y)>=8) or (length(y)=0)then f:=false;
    e:='';
    for uu:=i+1 to j do e:=e+s[uu];
    if ((e[1]='0') and (lengtH(e)>1)) or (lengtH(e)>=8) or (length(e)=0)then f:=false;
    h:='';
     for uu:=j+1 to lengtH(s) do h:=h+s[uu];
    if ((h[1]='0') and (lengtH(h)>1)) or (length(h)>=8) or (length(h)=0)then f:=false;
     val(y,x,code);
     val(e,r,code);
     val(h,z,code);
     if x>1000000 then f:=false;
     if r>1000000 then f:=false;
     if z>1000000 then f:=false;
     if (f) and (x+r+z>ans)  then ans:=x+r+z;
     inc(j);
    end;
    inc(I);
   end;
   writeln(ans);
end.

const   fi='';
        fo='';
        MaxQ=1000000;
var     i,j,k,res,a,b,c,d:longint;
        s1,s2,s3,s:string;
function    check(s1:string):boolean;
begin
        if ((s1[1] = '0') and (length(s1) > 1)) or (length(s1) >7) then exit(false);
        exit(true);
end;

begin
        assign(input,fi);
        reset(input);
        assign(output,fo);
        rewrite(output);
        read(s);
        res:=-1;
        d:=length(s);
        for i:=1 to d-2 do
          begin
            for j:=i+1 to d-1 do
              begin
                    s1:=copy(s,1,i);
                    s2:=copy(s,i+1,j-i);
                    s3:=copy(s,j+1,d-j);
                    if (not check(s1)) or (not check(s2)) or (not check(s3)) then continue;
                    val(s1,a);
                    val(s2,b);
                    val(s3,c);
                    if (a > MaxQ) or (b > MaxQ) or (c>MaxQ) then continue;
                    k:=a+b+c;
                    if k > res then res:=k;
              end;
          end;
        write(res);
end.

var
        st,st1,st2,st3:string;
        i,j,max1,len,shu1,shu2,shu3,sum:longint;
begin
        readln(st);
        len:=length(st);
        max1:=-1;
        if length(st)<=21 then
        for i:=2 to len-1 do
                for j:=i+1 to len do
                begin
                        st1:=copy(st,1,i-1);
                        st2:=copy(st,i,j-i);
                        st3:=copy(st,j,len-j+1);
                        if length(st1)>7 then continue;
                        if length(st2)>7 then continue;
                        if length(st3)>7 then continue;
                        if(length(st1)>1)and(st1[1]='0')then continue;
                        if(length(st2)>1)and(st2[1]='0')then continue;
                        if(length(st3)>1)and(st3[1]='0')then continue;
                        val(st1,shu1);
                        val(st2,shu2);
                        val(st3,shu3);
                        if(shu1>1000000)or(shu2>1000000)or(shu3>1000000)then
                                continue;
                        sum:=shu1+shu2+shu3;
                        if sum>max1 then max1:=sum;
                end;
        writeln(max1);
        readln;
end.

Uses sysutils;
Var N,i,j,k,l,m,t,r,i1,j1,k1,t1,t2,t3,t4,t5,t6,r1,r2,r3:longint;
d:char;
s,s1,s2,s3:string;
begin
{assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(Output);}
Readln(s);
N:=length(s);
t:=-1;
For i:=1 to 7 do begin
  For j:=i+1 to i+7 do begin
    For k:=j+1 to j+7 do begin
      if k=N then begin
        s1:='';
        s2:='';
        s3:='';
        For i1:=1 to i do
          s1:=s1+s[i1];
        For j1:=i+1 to j do
          s2:=s2+s[j1];
        For k1:=j+1 to k do
          s3:=s3+s[k1];
          t1:=strtoint(s1);
          t2:=strtoint(s2);
          t3:=strtoint(s3);
          t4:=t1;
          t5:=t2;
          t6:=t3;
          r1:=0;
          r2:=0;
          r3:=0;
          while t4>0 do begin
            inc(r1);
            t4:=t4 div 10;
          end;
          while t5>0 do begin
            inc(r2);
            t5:=t5 div 10;
          end;
          while t6>0 do begin
            inc(r3);
            t6:=t6 div 10;
          end;
          if r1=0 then
            inc(r1);
          if r2=0 then
            inc(r2);
          if r3=0 then
            inc(r3);
          if r1=i then begin
            if r2=j-i then begin
              if r3=k-j then begin
              if (t1<=1000000) and (t2<=1000000) and
              (t3<=1000000) then begin
                if t<t1+t2+t3 then
                  t:=t1+t2+t3;
              end;
            end;
          end;
        end;
      end;
    end;
  end;
end;
writeln(t);
end.

Var s:string;
    i,j:longint;
    max,sum,now:int64;
    q:longint;
    a,b,c:int64;

Procedure check(ii,jj:longint);
Var s1,s2,s3:string;  q:longint; a,b,c:int64;
Begin

s1:=''; s2:=''; s3:='';

for q:=1 to i-1 do s1:=s1+s[q];
for q:=i to j-1 do s2:=s2+s[q];
for q:=j to length(s) do s3:=s3+s[q];

if (length(s1)>1)and(s1[1]='0') then exit;
if (length(s2)>1)and(s2[1]='0') then exit;
if (length(s3)>1)and(s3[1]='0') then exit;
if (length(s1)>7) then exit;
if (length(s2)>7) then exit;
if (length(s3)>7) then exit;
if (length(s1)=7)and(s1<>'1000000') then exit;
if (length(s2)=7)and(s2<>'1000000') then exit;
if (length(s3)=7)and(s3<>'1000000') then exit;

a:=0; for q:=1 to length(s1) do a:=a*10+byte(s1[q])-48;
b:=0; for q:=1 to length(s2) do b:=b*10+byte(s2[q])-48;
c:=0; for q:=1 to length(s3) do c:=c*10+byte(s3[q])-48;

if a+b+c>max then max:=a+b+c;
end;

Begin

Readln(s); max:=-1; a:=-1; b:=-1; c:=-1;

for i:=2 to length(s)-1 do
 for j:=i+1 to length(s) do if (i<=length(s))and(j<=length(s)) then check(i,j);

 WritelN(max);

 End.

var st,st1,st2,st3:string;
   i,j,max,l,score,p1,p2,p3:longint;
begin
  readln(st);
  l:=length(st);
  max:=-1;
  for i:=1 to l-2 do
    for j:=i+1 to l-1 do
      begin
        st1:=copy(st,1,i);
        st2:=copy(st,i+1,j-i);
        st3:=copy(st,j+1,255);
        if(length(st1)>7)or(length(st2)>7)or(length(st3)>7)then continue;
        if(length(st1)>1)and(st1[1]='0')then continue;
        if(length(st2)>1)and(st2[1]='0')then continue;
        if(length(st3)>1)and(st3[1]='0')then continue;
        val(st1,p1);val(st2,p2);val(st3,p3);
        if(p1>1000000)or(p2>1000000)or(p3>1000000) then continue;
        score:=p1+p2+p3;
        if score>max then max:=score;
      end;
  writeln(max);
end.

var s,s1,s2,s3:string;
    i,j,k:longint;
    data1,data2,data3:int64;
    error,max:longint;

function check(s:string):boolean;
begin
 if (length(s)>=2) and (S[1]='0') then
  check:=false else check:=true;
end;

begin
 readln(S);
 max:=-1;
 for i:= 1 to length(s) do
  for j:= i+1 to length(s)-1 do
   begin
    s1:=copy(s,1,i);
    s2:=copy(s,i+1,j-i);
    s3:=copy(s,j+1,length(s)-j);
   if length(s1)>7 then continue;
   if length(s2)>7 then continue;
   if length(s3)>7 then continue;
    if check(s1)=false then continue;
    if check(S2)=false then continue;
    if check(s3)=false then continue;
    val(s1,data1,error);
    val(s2,data2,error);
    val(S3,data3,error);
    if data1>1000000 then continue;
    if data2>1000000 then continue;
    if data3>1000000 then continue;
    if data1+Data2+data3>max then max:=data1+Data2+data3;
   end;
  writeln(max);
end.

program va;
var t:string;
    i,j,k:longint;
    t1,t2,t3,max,min:int64;
    s1,s2,s3:string;
function pd(a,b,c:string):boolean;
var t:longint;
begin
pd:=true;
if (a[1]='0') and (length(a)>1) then exit(false);
if (b[1]='0') and (length(b)>1) then exit(false);
if (c[1]='0') and (length(c)>1) then exit(false);
end;
procedure sp;
begin
 write('-1');
 halt;
end;
begin
 read(t);
 max:=-1;
 if length(t)>21 then sp;
 for i:=1 to length(t) do
  for j:=1 to length(t) do
   for k:=1 to length(t) do
     if (j>i) and (k>j)  then
     begin

     s1:=copy(t,1,(j-1));
     s2:=copy(t,j,(k-j));
     s3:=copy(t,k,length(t));
     if pd(s1,s2,s3)=false then continue;
     if length(s3)>7 then continue;
     if length(s2)>7 then continue;
     if length(s1)>7 then continue;
     val(s1,t1); val(s2,t2); val(s3,t3);
     if t1>1000000 then continue;
     if t2>1000000 then continue;
     if t3>1000000 then continue;
     if max<(t1+t2+t3) then max:=t1+t2+t3;
    end;
 write(max);
end.

uses  math;
var
  a:array[0..300] of longint;

  f,next,head,nom,zz,d:array[0..222222] of longint;

  ff:array[1..33333] of boolean;
  x,y,j,z,v,i,n,n1,n2,ans,k,p,m:longint;

 s,s1:ansistring;
  c1,c2:char;

function pr(a,b:longint):longint;
begin
  if b-a>7 then exit(-10000000);
  if (b-a>0)and(s[a]='0') then exit(-10000000);
  x:=0;
  for y:=a to b do
   x:=x*10+ord(s[y])-48;
  if x>1000000 then exit(-10000000) else exit(x);

end;

begin
//assign(input,'input.txt');reset(input);
  readln(s);
  n:=length(s);
  m:=-1;
  for i:=1 to n-2 do
   for j:=i+1 to n-1 do

     begin
       p:=pr(1,i)+pr(i+1,j)+pr(j+1,n);
       if p>m then m:=p;

     end;

  write(m);
end.

var n,i,j:longint;
q,s:string;
max,ss,x:longint;
code:integer;
 begin
  readln(s);
  n:=length(s);
  max:=-1;

  for i:=1 to n do
    if i<=7 then
      for j:=i+1 to n-1 do
        if j-i<=7 then
            if n-j<=7 then
              begin
               ss:=0;
               q:=copy(s,1,i);
               if (q[1]='0')and(length(q)>1) then continue;

               val(q,x,code);
               if x>1000000 then continue;

               ss:=ss+x;

               q:=copy(s,i+1,j-i);
               if (q[1]='0')and(length(q)>1) then continue;

               val(q,x,code);
               if x>1000000 then continue;

               ss:=ss+x;

               q:=copy(s,j+1,n-j);
               if (q[1]='0')and(length(q)>1) then continue;

               val(q,x,code);
               if x>1000000 then continue;

               ss:=ss+x;

               if ss>max then max:=ss;
              end;

  writeln(max);

 end.

Program PA;
 const maxn=36;
       maxd=1000000;

 var s:string;
     sa,sb,sc:string;
      sum,code,a,b,c,l:longint;

 procedure main;
 var i,j:longint;
  begin
   readln(s);
   l:=length(s);
   sum:=-1;
   for i:=1 to l-2 do
    for j:=i+1 to l-1 do
     begin
      sa:=copy(s,1,i);
      sb:=copy(s,i+1,j-i);
      sc:=copy(s,j+1,l-j);
      if length(sa)>8 then continue;
      if length(sb)>8 then continue;
      if length(sc)>8 then continue;
      val(sa,a,code);
      val(sb,b,code);
      val(sc,c,code);
      if (sa[1]='0')and(length(sa)>1) then continue;
      if (sb[1]='0')and(length(sb)>1) then continue;
      if (sc[1]='0')and(length(sc)>1) then continue;
      if a>maxd then continue;
      if b>maxd then continue;
      if c>maxd then continue;
      if sum<a+b+c then sum:=a+b+c;
     end;
  if sum=-1 then writeln(-1) else writeln(sum);
 end;

begin
 {assign(input,'PA.in');
 assign(output,'PA.out');
 reset(input);
 rewrite(output);}
 main;
 {close(input);
 close(output);}
end.

const
 e=1000000;
var
 s:ansistring;
 i,m,n,k,l,w,j,w1,w2,w3,res:longint;
begin
 readln(s);
 n:=length(s);
 res:=-1;
 for i:=1 to n do if i<=7 then
 begin
  for j:=i+1 to n-1 do if j-i<=7 then if n-j<=7 then
  begin
   if ((s[1]='0')and(i<>1))
   or ((s[i+1]='0')and(j-i<>1))
   or ((s[j+1]='0')and(n-j<>1)) then continue;
   val(copy(s,1,i),w1);
   val(copy(s,i+1,j-i),w2);
   val(copy(s,j+1,n),w3);
   if (w1>e)or(w2>e)or(w3>e) then continue;
   if w1+w2+w3>res then res:=w1+w2+w3;
  end;
 end;
 writeln(res);
end.

const fin='';
    fout='';
var n,max:longint;
    st:string;
     f,g:text;
function tong(x,y:integer):integer;
var i,j,code:integer;
    so:longint;
    s1:string;
begin
    tong:=1; s1:='';
    if (y-x+1<=7) and ((st[x]<>'0') or (y-x+1=1)) then
     begin
        for i:=x to y do s1:=s1+st[i];
        val(s1,so,code);
        if so>1000000 then tong:=0
         else n:=n+so;
     end
     else tong:=0;
end;
procedure xuli;
var i,j,lc,p:integer;
begin
    read(f,st); p:=0;
     max:=0; lc:=0;
     for i:=1 to length(st)-2 do
        for j:=i+1 to length(st)-1 do
        begin
          n:=0;
          if (tong(1,i)<>1) then break
          else
          if (tong(i+1,j)=1) and (tong(j+1,length(st))=1) then
         if n>=max then
            begin
            max:=n;
               lc:=1;
               end;
        end;
     if lc=1 then
     write(g,max)
     else write(g,-1);
end;
begin
    assign(f,fin);reset(f);
     assign(g,fout);rewrite(g);
     xuli;
     close(g);
end.

program sdhkjf;
var a:array[1..100000] of longint;
i,j,n,i1,i2,max:longint;
s,s1,s3,s2:string;
c:char;
function func(r:string):boolean;
begin
 if r='1000000' then func:=true else
 if ((length(r)>1) and (r[1]='0')) or (length(r)>6) then func:=false else
 func:=true;
end;
procedure proc(r1,r2,r3:string);
var t1,t2,t3:longint;
y:integer;
begin
val(r1,t1,y);
val(r2,t2,y);
val(r3,t3,y);
if t1+t2+t3>max then max:=t1+t2+t3;
end;
begin
read(s);max:=-1;
n:=length(s);
if (n>21) or (n<3) then begin writeln(-1); exit; end;
for i:=1 to n-2 do
 for j:=1 to n-i-1 do
  begin
   s1:=copy(s,1,i);
   s2:=copy(s,i+1,j);
   s3:=copy(s,j+i+1,n-i-j);
   if (i<8) and (j<8) and (n-i-j<8) then  if (func(s1)) and (func(s2)) and (func(s3)) then proc(s1,s2,s3);
  end;
writeln(max);
end.

uses math;

var
	s, a, b, c : string;
	atb, i, j, t, sum,  k : longint;
	bool : boolean;

begin
	atb := -1;
	readln(s);
	for i := 1 to length(s) - 2 do for j := i + 1 to length(s) - 1 do begin
		bool := true;
		a := copy(s, 1, i);
		b := copy(s, i + 1, j - i);
		c := copy(s, j + 1, length(s) - j);
		if (length(a) > 7) or (length(b) > 7) or (length(c) > 7) then bool := false;
		if (a[1] = '0') and (length(a) > 1) then bool := false;
		if (b[1] = '0') and (length(b) > 1) then bool := false;
		if (c[1] = '0') and (length(c) > 1) then bool := false;
		if (length(a) = 7) and (a <> '1000000') then bool := false;
		if (length(b) = 7) and (b <> '1000000') then bool := false;
		if (length(c) = 7) and (c <> '1000000') then bool := false;

		if bool then begin
			val(a, sum, k);
			val(b, t, k); inc(sum, t);
			val(c, t, k); inc(sum, t);

			atb := max(atb, sum);

		end;

	end;

	writeln(atb);

end.

uses sysutils;
var s:string;
    max:longint;
    a:array [1..3] of longint;
procedure rec(k,l:longint);
var i:longint;
begin
  if (k=4) then
    begin
      if l=length(s) then if a[1]+a[2]+a[3]>max then max:=a[1]+a[2]+a[3];
    end
  else
    begin
      a[k]:=0;
      for i:=l+1 to length(s) do
        begin
          a[k]:=a[k]*10+strtoint(s[i]);
          if a[k]>1000000 then break;
          rec(k+1,i);
          if a[k]=0 then break;
        end;
    end;
end;
begin
  readln(s);
  max:=-1;
  rec(1,0);
  writeln(max);
end.

var
 s,p1,p2,p3: string;
 n,i,j,k: longint;
 x,y,z,ans: int64;

begin
  readln(s);
  ans := -1;
  n := length(s);
  p1 := '';
  for i := 1 to 7 do
    begin
	 if i > n-2 then break;
	 p1 := p1 + s[i];
	 p2 := '';
	 if (length(p1)>1) and (p1[1]='0') then break;
	  for j := i+1 to i+7 do
	    begin
		 if j > n-1 then break;
		  p2 := p2 + s[j];
		   p3 := '';
		   if n-j > 7 then continue;
		  for k := j+1 to n do
		    p3 := p3 + s[k];
		  if (length(p2)>1) and (p2[1]='0') then break;
		  if (length(p3)>1) and (p3[1]='0') then continue;
		  val(p1,x); val(p2,y); val(p3,z);
		  if (x>1000000) or (y>1000000) or (z>1000000) then continue;
		  if x+y+z > ans then ans := x + y + z;
		end;
	end;
	writeln(ans);
end.

uses sysutils;
var s, x, y, z: string;
    i, j, l: byte;
    t, m, a, b, c: longint;
begin
        readln(s);
        l := length(s);
        if l < 3 then
        begin
                writeln(-1);
                exit;
        end;
        m := -1;
        for i := 2 to l - 1 do
                for j := i + 1 to l do
                begin
                        if (i > 8) or (j - i > 7) or (l - j > 6) then
                                continue;
                        x := copy(s, 1, i - 1);
                        y := copy(s, i, j - i);
                        z := copy(s, j, l - j + 1);
                        a := strtoint(x);
                        b := strtoint(y);
                        c := strtoint(z);
                        if (a > 1000000) or (b > 1000000) or (c > 1000000) then
                                continue;
                        if ((x[1] = '0') and (i > 2)) or ((y[1] = '0') and (j > i + 1)) or ((z[1] = '0') and (l > j)) then
                                continue;
                        t := a + b + c;
                        if t > m then
                                m := t;
                end;
        writeln(m);
end.

var
  j,i,ans,x,y,z:longint;
  p,s:ansistring;

begin
  readln(s);
  ans:=-1;
  for i:=1 to length(s)-2 do
    for j:=i+1 to length(s)-1 do begin
      if (i>7)then continue;
      if (j-i>7)then continue;
      if (length(s)-j>7)then continue;
      if (s[1]='0')and(i>1)then continue;
      if (s[i+1]='0')and(j>i+1)then continue;
      if (s[j+1]='0')and(j+1<length(s))then continue;
      p:=s;
      val(copy(p,1,i),x);
      delete(p,1,i);
      val(copy(p,1,j-i),y);
      delete(p,1,j-i);
      val(p,z);
      if (x>1000000)then continue;
      if (y>1000000)then continue;
      if (z>1000000)then continue;
      if (x+y+z>ans)then ans:=x+y+z;
    end;
  writeln(ans);
end.

var s, a,b,c: String;
    i,j,n, x,y,z, ans, code: LongInt;
begin
  Readln(s);
  ans:=-1;
  n:=Length(s);

  if (n>21) or (n<3) then begin Writeln(-1); halt(0); end;

  for i:=1 to n-2 do
    for j:=i+1 to n-1 do
    begin
      a:=Copy(s,1,i);
      b:=Copy(s,i+1,j-i);
      c:=Copy(s,j+1,n-j);

      val(a,x,code);
      val(b,y,code);
      val(c,z,code);

      if (x>1000000) or (y>1000000) or (z>1000000) then continue;
      if (a[1]='0') and (Length(a)>1) or (b[1]='0') and (Length(b)>1) or (c[1]='0') and (Length(c)>1) then continue;

      if x+y+z>ans then ans:=x+y+z;
    end;

  Writeln(ans);
end.

program Prog;

{$APPTYPE CONSOLE}

{$R *.res}
uses sysutils;
var
st,a,s,d:string;
n,sum,max:longint;
i,j,k:integer;

begin
readln(st);
n:=length(st);
max:=-1;
if n>2 then
for i := 1 to n-2 do
  for j := i+1 to n-1 do
    begin
      a:=copy(st,1,i);
      s:=copy(st,i+1,j-i);
      d:=copy(st,j+1,n-j);
      if (length(a)<8)and(length(s)<8)and(length(d)<8) then
        if (length(inttostr(strtoint(a)))=length(a))and(length(inttostr(strtoint(s)))=length(s))and(length(inttostr(strtoint(d)))=length(d)) then begin
          sum:=strtoint(a)+strtoint(s)+strtoint(d);
          if (sum>max)and(strtoint(a)<=1000000)and(strtoint(s)<=1000000)and(strtoint(d)<=1000000) then max:=sum;
        end;
    end;
writeln(max);
readln;
end.

Var s,s1,s2,s3:String;
    i,j,k,max,p,x1,x2,x3,k1,k2,k3,i1:LongInt;
  begin
    ReadLn(s);
    max:=-maxLongInt;
    For i:=1 to 7 do
     begin
       For j:=1 to 7 do
        begin
          For k:=1 to 7 do
           begin
             if i+j+k=Length(s) then
              begin
                s1:=copy(s,1,i);
                s2:=copy(s,i+1,j);
                s3:=copy(s,i+j+1,k);
                k1:=0;
                k2:=0;
                k3:=0;
                For i1:=1 to LEngth(s1) do
                 begin

                   if (s1[i1]='0') then k1:=k1+1;
                 end;
                For i1:=1 to LEngth(s2) do
                 begin
                   if (s2[i1]='0') then k2:=k2+1;
                 end;
                For i1:=1 to LEngth(s3) do
                 begin
                   if (s3[i1]='0') then k3:=k3+1;
                 end;
                if ((s1[1]<>'0') or ((k1=Length(s1)) and (i=1))) and
                ((s2[1]<>'0') or ((k2=Length(s2)) and (j=1))) and ((s3[1]<>'0') or ((k3=Length(s3)) and (k=1))) then
                begin
                Val(copy(s,1,i),x1,p);
                Val(copy(s,i+1,j),x2,p);
                Val(copy(s,i+j+1,k),x3,p);
                if (x1<=1000000) and (x2<=1000000) and (x3<=1000000) then
                begin
                if x1+x2+x3>max then max:=x1+x2+x3;
                end;
                end
              end;
           end;
        end;
     end;
    if max=-maxLongInt then WriteLn(-1)
    else WriteLn(max);
  end.

(*
Problem		:	Codeforces_175A
Author		:	Shuriken
Start Time	:	2012-5-31 07:39
Finish Time	:
Result		:
Method		:	Brute Force
Errors		:
*)
Program CF_175A;
Uses Math;
Const
	maxn						=30+5;
Var
	s,s1,s2,s3					:string[maxn];
	ans							:longint;

Procedure Init;
Begin
	readln(s);
End;

Function Calc:longint;
Var a,b,c						:longint;
Begin
	if (length(s1)=0)or(length(s2)=0)or(length(s3)=0) then exit(-1);
	if (length(s1)>7)or(length(s2)>7)or(length(s3)>7) then exit(-1);
	if (length(s1)=7)and(s1<>'1000000') then exit(-1);
	if (length(s2)=7)and(s2<>'1000000') then exit(-1);
	if (length(s3)=7)and(s3<>'1000000') then exit(-1);
	if (length(s1)>1)and(s1[1]='0') then exit(-1);
	if (length(s2)>1)and(s2[1]='0') then exit(-1);
	if (length(s3)>1)and(s3[1]='0') then exit(-1);

	val(s1,a);
	val(s2,b);
	val(s3,c);
	exit(a+b+c);
End;

Procedure Main;
Var i,j							:longint;
Begin
	ans:=-1;

	if length(s)>21 then exit;

	for i:=1 to 7 do
		begin
			if length(s)-i<2 then break;
			s1:=s1+s[i];
			s2:='';
			for j:=i+1 to i+7 do
				begin
					if length(s)-j<1 then break;
					s2:=s2+s[j];
					s3:=copy(s,j+1,length(s)-j);
					ans:=max(ans,calc);
				end;
		end;
End;

Procedure Print;
Begin
	writeln(ans);
End;

Begin
	Init;
	Main;
	Print;
End.

var
  s,r1,r2,r3: string;
  er,n,a1,a2,rv1,rv2,rv3,sum,maxs: longint;

  function check(s1: string): boolean;
    var
      m: longint;
   begin
     m:=length(s1);
     if (m <= 0) or (m >= 8) or ((m = 7) and (s1 <> '1000000')) or ((m > 1) and (s1[1] = '0')) then exit(false);
     check:=true;
   end;

 begin
   read(s);
   n:=length(s);
   maxs:=-1;
   a2:=1;a1:=1;
   while a1 < 8 do
   begin
     while a2 < 8 do
     begin
       r1:=copy(s,1,a1);
       r2:=copy(s,a1+1,a2);
       r3:=copy(s,a1+a2+1,n-a1-a2);
       if not check(r1) then begin inc(a2);continue; end;
       if not check(r2) then begin inc(a2);continue; end;
       if not check(r3) then begin inc(a2);continue; end;
       val(r1,rv1,er);
       val(r2,rv2,er);
       val(r3,rv3,er);
       sum:=rv1+rv2+rv3;
       if sum > maxs then maxs:=sum;
       inc(a2);
     end;
     a1:=a1+1;a2:=1;
   end;
   write(maxs);
 end.

var n,i,j,a,b,c,l,k,max:longint;
    s,s1,s2,s3:string[35];
    p:integer;
begin
  readln(s);
  n:=length(s);
  if (n=3) and (s[1]='0') and (s[2]='0') and (s[3]='0') then
  begin
    writeln(0);
    exit;
  end;
   for j:=1 to n-2 do
   begin
     s1:=copy(s,1,j);
     for i:=1 to n-j-1 do
     begin
       s2:=copy(s,j+1,i);
       s3:=copy(s,j+i+1,n-i-j+1);
       if (length(s1)<8) and (length(s2)<8) and (length(s3)<8) then
       begin
         if ((s1[1]<>'0') or (length(s1)=1)) and
            ((s2[1]<>'0') or (length(s2)=1)) and
            ((s3[1]<>'0') or (length(s3)=1)) then
         begin
           val(s1,a,p);
           val(s2,b,p);
           val(s3,c,p);
           if (a<=1000000) and (b<=1000000) and (c<=1000000) then k:=a+b+c;
           if k>max then max:=k;
         end;
       end;
     end;
   end;
  if max=0 then write(-1)
           else write(max);
end.

var ss,s:string; a,b,c,k:extended;
    i,j:byte;
begin
readln(s);
k:=-1;
for i:=1 to length(s) do
 for j:=i+2 to length(s) do
  begin
   ss:=copy(s,1,i);
   val(ss,a);
   if length(ss)>=2 then if (ss[1]='0')or(a>1000000) then continue;
   ss:=copy(s,i+1,j-i-1);
   val(ss,b);
   if length(ss)>=2 then if (ss[1]='0')or(b>1000000) then continue;
   ss:=copy(s,j,length(s)-j+1);
   val(ss,c);
   if length(ss)>=2 then if (ss[1]='0')or(c>1000000) then continue;
   if a+b+c>k then k:=a+b+c;
  end;
writeln(k:0:0);
end.

{$mode objfpc}
var
s:string;

function min(x,y:longint):longint;
begin if x<y then exit(x) else exit(y); end;

function gl(x:longint):longint;
begin if x=0 then exit(1);
	gl:=0; while x>0 do begin inc(gl); x:=x div 10; end;
end;

procedure lemon();
var max,i,j,sc1,sc2,sc3,ccc,len:longint;
begin readln(s); len:=length(s);
	if length(s)>21 then begin writeln(-1); exit; end;
	max:=-1;
	for i:=1 to min(len,7) do
	begin val(copy(s,1,i),sc1,ccc);
		if (0<=sc1)and(sc1<=1000000)and(gl(sc1)=i) then
			for j:=i+1 to min(len,i+7) do
			begin val(copy(s,i+1,j-i),sc2,ccc);
				if (0<=sc2)and(sc2<=1000000)and(gl(sc2)=j-i) then
					if (len-j>=1)and(len-j<=7) then
					begin val(copy(s,j+1,len-j),sc3,ccc);
						if (0<=sc3)and(sc3<=1000000)and(gl(sc3)=len-j) then
							if sc1+sc2+sc3>max then
								max:=sc1+sc2+sc3;
					end;
			end;
	end;
	writeln(max);
end;

begin
{$ifndef ONLINE_JUDGE}
	assign(input,'A.in');
	reset(input);
{$endif}
lemon();
end.

program pr;
 const m = 1000000;

 var str:string;
     arr:array [1..30] of longint;
     len,i,j,res,a:longint;
     err:integer;

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

function f(a,b:longint):longint;
 var n,d,res,i:longint;
     w:boolean;
begin
 if ((arr[1] = 0) and (a > 2)) or ((arr[a] = 0) and (b - a > 1)) or ((arr[b] = 0) and (len - b > 0)) or (a > 8) or (b - a > 7) or (len - b > 7) then
 begin
  w:=true;
 end else
 begin
  w:=false;

  res:=0;

  n:=0;
  d:=1;
  for i:=(a - 1) downto 1 do
  begin
   inc(n, arr[i]*d);
   d:=d * 10;
  end;

  inc(res, n);

  if (n > m) then
   w:=true;

  n:=0;
  d:=1;
  for i:=(b - 1) downto a do
  begin
   inc(n, arr[i]*d);
   d:=d * 10;
  end;

  inc(res, n);

  if (n > m) then
   w:=true;

  n:=0;
  d:=1;
  for i:=len downto b do
  begin
   inc(n, arr[i]*d);
   d:=d * 10;
  end;

  inc(res, n);

  if (n > m) then
   w:=true;
 end;

 if (w) then
  f:=-1
 else
  f:=res;
end;

begin
 readln(str);
 len:=Length(str);

 for i:=1 to len do
  val(str[i], arr[i], err);

 res:=-1;

 for i:=2 to min(8, len - 1) do
  for j:=(i + 1) to len do
  begin
   a:=f(i,j);

   if (a > res) then
    res:=a;
  end;

  writeln(res);
end.

var
    t,e,x,x1,d,g,i,i1,h,j,j1,j2,k,l,i2:longint;
    s:string;
    a:array [1..30] of longint;
begin
readln(s);
g:=length(s);
for i:=1 to g do
    a[i]:=ord(s[i])-48;
l:=-1;
{if g>7 then t:=7
else t:=g;   }
for i:=1 to 7 do
    for i1:=1 to 7 do
    begin
         j:=0;
         j1:=0;
         j2:=0;
         k:=0;
         h:=1;
         for i2:=i downto 1 do
         begin
              j:=j+(a[i2]*h);
              h:=h*10;
         end;
         h:=1;
         for i2:=i+i1 downto i+1 do
         begin
              j1:=j1+(a[i2]*h);
              h:=h*10;
         end;
         d:=g-i-i1;
         if g-i-i1<=7 then
         begin
            k:=1;
            h:=1;
            for i2:=g downto i+i1+1 do
            begin
              j2:=j2+(a[i2]*h);
              h:=h*10;
            end;
         end;
         if (j<=1000000) and (j1<=1000000) and (j2<=1000000) and (k=1) then
            if ((a[1]<>0) or (i<2)) and ((a[i+1]<>0) or (i1<2)) and ((a[i+i1+1]<>0) or (d<2)) then
                if (j+j1+j2>l) and (i<=g) and (i1<=g) and (i+i1<g) then
                begin
                     l:=j+j1+j2;
                     e:=1;
                     x:=i;
                     x1:=i1;
                end;
    end;
if e=0 then write(-1)
else write(l);
end.

program sol;
{
Problem A
Robot Bicorn Attack
start at 16:30
}
var
    s:string[32];
    s1,s2,s3,i,j,ans:longint;
function tr(const s:string):longint;
var code:integer; tmp:longint;
begin
    if length(s)=0 then exit(-1);
    if length(s)>7 then exit(-1);
    if length(s)=1 then exit(ord(s[1])-48);
    if s[1]='0' then exit(-1);
    val(s,tmp,code);
    if tmp>1000000 then exit(-1);
    exit(tmp);
end;
begin
    readln(s); ans:=-1;
    for i:=1 to length(s) do begin
	s1:=tr(copy(s,1,i));
	if s1=-1 then continue;
	for j:=1 to length(s)-i do begin
	    s2:=tr(copy(s,i+1,j));
	    if s2=-1 then continue;
	    s3:=tr(copy(s,i+j+1,30));
	    if s3=-1 then continue;
	    if s1+s2+s3>ans then ans:=s1+s2+s3;
	end;
    end;
    writeln(ans);
end.

uses math;
var
s1,s2,s3,s:string;
b1,b2,b3,res:longint;
i,j:longint;
y:integer;

procedure NO;
begin
 writeln('-1');
 halt;
end;

function ch(c:char):boolean;
begin
if c in['0'..'9'] then ch:=true else ch:=false;
end;

function can(s:string):boolean;
begin
if s='1000000' then can:=true else
if length(s)>6 then can:=false else
if s='0' then can:=true else
if s[1]='0' then can:=false else
can:=true;
end;

begin
 readln(s); res:=-1;
// if s[1]='0' then no;
 for i:=1 to length(s) do if not ch(s[i]) then no;

 for i:=2 to length(s)-1 do
   for j:=i+1 to length(s) do
     begin
     s1:=copy(s,1,i-1);
     s2:=copy(s,i,j-i);
     s3:=copy(s,j,length(s)-j+1);
//           writeln(s1,' ',s2,' ',s3);
     if (can(s1)) and (can(s2)) and (can(s3)) then
      begin
      val(s1,b1,y);
      val(s2,b2,y);
      val(s3,b3,y);
     // writeln(s1,' ',s2,' ',s3);
      res:=max(res,b1+b2+b3);
      end;
     end;

writeln(res);
end.

var i,n,q1,q2,q3,j,f,ans:longint;
   s,s1,s2,s3:string;
begin            {
assign (input,'input.txt');
assign (output,'output.txt');
reset (input);
rewrite (output);  }
readln (s);
n:=length(s);
ans:=-1;
for i:=1 to n do
 for j:=i+1 to n-1 do
   begin
     s1:=copy(s,1,i);
     s2:=copy(s,i+1,j-i);
     s3:=copy(s,j+1,n-j);
     if (length(s1)>7) or (length(s2)>7) or (length(s3)>7) then continue;
     if ((s1[1]='0') and (length(s1)>1)) or ((s2[1]='0') and (length(s2)>1)) or ((s3[1]='0') and (length(s3)>1)) then continue;
     val (s1,q1,f);
     val (s2,q2,f);
     val (s3,q3,f);
     if (q1>1000000) or (q2>1000000) or (q3>1000000) then continue;
     if q1+q2+q3>ans then ans:=q1+q2+q3;
   end;
write (ans);
end.

var a:array[1..40] of longint;
    answer,x1,x2,x3:int64;
    i,j,n:longint;
    ch:char;

    function find(l,r:longint):int64;
     var res:int64;
         i:longint;
          begin
           res:=0;
           if (r-l+1>1) and (a[l]=0) then exit(-1);
           for i:=l to r do
            begin
             res:=res*10+a[i];
             if res>1000000 then exit(-1);
            end;
          exit(res);
         end;

     begin
       read(ch);
       while ch in['0'..'9'] do
        begin
         inc(n);
         a[n]:=ord(ch)-ord('0');
         read(ch);
        end;
       answer:=-1;
       for i:=1 to n-2 do
       for j:=i+1 to n-1 do
        begin
         x1:=find(1,i);
         x2:=find(i+1,j);
         x3:=find(j+1,n);
         if (x1<0) or (x2<0) or (x3<0) then continue;
         if x1+x2+x3>answer then answer:=x1+x2+x3;
        end;
      writeln(answer);
   end.

const nn=100;
var a:array[0..nn] of longint;   tt:integer;
    n,i,j,y,z,t,k,x:longint;s:string;
begin
 read(s);
 y:=-1;
 z:=length(s);
 for i:=1 to 7 do
 begin
  if ((i>1)and(s[1]<>'0'))or (i=1) then
 begin
  val(copy(s,1,i),x,tt);
  if x<1000001 then
  begin
  for j:=1 to 7 do
  if ((i+j)<z) and(z-i-j<8)then
  begin
   if ((j>1)and(s[i+1]<>'0'))or (j=1) then
   begin
   val(copy(s,1+i,j),k,tt);
   if k<1000001 then begin
   if ((z-i-j>0)and(s[i+j+1]<>'0'))or (z-i-j=1) then
   begin
   val(copy(s,1+i+j,z-i-j),t,tt);
   if t<1000001 then begin
   n:=x+k+t;
   if (n>y) then y:=n;
   end;                  end;
   end;
  end;
  end;                           end
; end;
 end;
write(y);
end.

Program Launcelot;
var s,s1,s2,s3:string;
    i,j,k,n,ans,ii,aans:longint;
    l,a:array[1..3]of longint;

begin
  readln(s);
  n:=length(s);
  aans:= -1;
  for i:=1 to n-2 do
    for j:=1 to n-i-1 do
      begin
        ans:=-1;
        s1:=copy(s,1,i);
        s2:=copy(s,i+1,j);
        s3:=copy(s,i+j+1,n-i-j);
        l[1]:=length(s1); l[2]:=length(s2); l[3]:=length(s3);
        if (i>7)or(j>7)or(n-i-j>7) then continue;
        if (l[1]>1)and(s1[1]='0') then continue;
        if (l[2]>1)and(s2[1]='0') then continue;
        if (l[3]>1)and(s3[1]='0') then continue;
        fillchar(a,sizeof(a),0);
        for ii:=1 to l[1] do
          a[1]:=a[1]*10+ord(s1[ii])-ord('0');
        for ii:=1 to l[2] do
          a[2]:=a[2]*10+ord(s2[ii])-ord('0');
        for ii:=1 to l[3] do
          a[3]:=a[3]*10+ord(s3[ii])-ord('0');
        if (a[1]<=1000000)and(a[2]<=1000000)and(a[3]<=1000000) then
            ans:=a[1]+a[2]+a[3]
        else ans:=-1;
        if (ans>aans) then aans:=ans;
      end;
  writeln(aans);
end.

var z,x,c,v,len,fl:longint;
sum,shsum,sh:int64;
a,chis:string;
begin
readln(a);

sum:=-1;
len:=length(a);
for z:=1 to len-2 do begin
for x:= z+1 to len-1 do begin
shsum:=0;
fl:=0;
chis:='';
for c:=1 to z do
chis:=chis+a[c];
if length(chis)>7 then
fl:=1;
if (chis[1]='0') and (length(chis)>1) then
fl:=1;
val(chis,sh);
if sh>1000000 then fl:=1;
shsum:=shsum+sh;
chis:='';
for c:=z+1 to x do
chis:=chis+a[c];
if length(chis)>7 then
fl:=1;
if (chis[1]='0') and (length(chis)>1) then
fl:=1;
val(chis,sh);
if sh>1000000 then fl:=1;
shsum:=shsum+sh;
chis:='';
for c:=x+1 to len do
chis:=chis+a[c];
if length(chis)>7 then
fl:=1;
if (chis[1]='0') and (length(chis)>1) then
fl:=1;
val(chis,sh);
if sh>1000000 then
 fl:=1;
shsum:=shsum+sh;
if (shsum>sum) and (fl<>1) then
sum:=shsum;
end;
end;
writeln(sum);
end.

program pr1;

{$APPTYPE CONSOLE}

const nn=1001;
 eps=0.0000000001;  nnn=20000;
 label 1,2,3,4;
var kk,pp,x,y,t,tt,k,i3,i0,i1,i2,p3,pgor,pver,p,step,i,j:longint;
kolraz,rr,s1,mmin,imin,s,x0,y0,w,vp,vd,f,ii,n,ot,modul,p1,p2,besk,l,m,k1,k2,a2,jj:int64;
koef:double;  ch,ch1,ch2:char;
pr,vrag:array [-1..10000 ] of boolean;
gr:array[0..nn,0..nn] of longint;
cc,bb,numgor,kol,dd:array[0..10000] of longint;
 oldmingor,oldminver,mingor,minver:array[0..1000] of longint;
sss,sss1,sss2,sss3: string;

r,a1,b1:array[-2..200000] of int64;
c:array[0..200000,0..2] of longint;
ss:array[0..30000] of string;
flag2,flag1,flag:boolean;
verot:double;
name:array[0..200] of string;
function min (a,b:longint):longint;begin min:=b;if a<b then min:=a;  end;
function max (a,b:longint):longint;begin max:=b;if a>b then max:=a;  end;

function nod(a,b:longint):longint; var p,t:longint;
begin 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 luck(a:longint):boolean;
 var i,j,k:longint;flag:boolean;
 c: array[0..10] of longint;
begin
  flag:=true;  j:=0;
  k:=a;
  while k>0 do begin inc(j); c[j]:=k mod 10; k:= k div 10; {writeln(j,' uu ',k); }  end;
 for i:=1 to j do if (c[i]<>4)and(c[i]<>7) then flag:=false;
 luck:=flag;
end;

  { function dist(i0,i1:longint):longint;
   var i,j,k,mmin,imin:longint; pr:array[0..3000] of boolean;
      dd:array[0..10000] of longint;
 begin  for i:=1 to n do pr[i]:=false;
   pr[i0]:=true;  dd[i0]:=0;
   for i:=1 to n do if not pr[i] then dd[i]:=gr[i0,i];
     k:=1;
       while k<n do
    begin
       inc(k);
        imin:=1; mmin:=1000000;
        for i:=1 to n do if (dd[i]<mmin) and (not pr[i]) then
          begin  imin:=i;mmin:=dd[i];   end;
       pr[imin]:=true;
       for i:=1 to n do if not pr[i] then dd[i]:=min(dd[i],dd[imin]+gr[imin,i]);

    end;

 dist:=dd[i1];

 end;  }

   function good(ss:string):boolean; var i,j,k,s:longint; fl:boolean;
 begin k:=length(ss);

   fl:=true;  if k>7 then fl:=false; if k<1 then fl:=false;
    if (ss[1]='0')and(k>1) then fl:=false;
   s:=0; for i:=1 to k do s:=10*s+ord(ss[i])-48;
    if s>1000000  then fl:=false;
      good:=fl;
 end;

   function ttt(ss:string):longint; var i,j,k,s:longint; fl:boolean;
 begin k:=length(ss);
   s:=0; for i:=1 to k do s:=10*s+ord(ss[i])-48;
      ttt:=s;
 end;

         begin
{assign (input,'input.txt');reset(input);
      assign (output,'output.txt'); rewrite(output);
}  readln(sss); n:=length(sss);
   {writeln(ttt('123')); }
   ot:=-1;
   for i:=1 to n-2 do for j:=i+1 to n-1 do
     begin
        sss1:='';sss2:='';sss3:='';
         for t:=1 to i do sss1:=sss1+sss[t];
         for t:=i+1 to j do sss2:=sss2+sss[t];
         for t:=j+1 to n do sss3:=sss3+sss[t];
     { writeln(sss1,' ',sss2,' ',sss3); writeln;
     } if good(sss1)and good(sss2) and good(sss3) then
        begin
           if ttt(sss1)+ttt(sss2)+ttt(sss3)>ot then ot:=ttt(sss1)+ttt(sss2)+ttt(sss3);
           {writeln('ot=',ot); }
        end;

     end;

   writeln(ot);

   1:
            close(output);
end.

{$R+ Q+ I+}
{$APPTYPE CONSOLE}
uses
  SysUtils;
var
   n,i,j,k,kol,max : integer;
   str1,str,str2,str3 : string;
begin
     read(str);
     max := low(max);
     n := length(str);
     str1:='';
     for i := 1 to n - 2 do begin
         if i >= 8 then break;
         str1 := str1 + str[i];
         if strtoint(str1) > 1000000  then break;
         if (str1[1] = '0') and (length(str1) > 1) then continue;
         str2 := '';
         for j := i + 1 to n - 1 do begin
             if j - i >= 8 then break;
             str2 := str2 + str[j];
             if (str2[1] = '0') and (length(str2) > 1) then continue;
             if strtoint(str2) > 1000000 then break;
             str3 := '';
             if n - j >= 8 then continue;
             for k := j + 1 to n do str3 := str3 + str[k];
             if (str3[1] = '0') and (length(str3) > 1) then continue;
             kol := 0;
             if strtoint(str3) > 1000000 then continue;
             kol := kol + strtoint(str1) + strtoint(str2) + strtoint(str3);
             if kol > max then max := kol;
         end;
     end;
     if max = low(max) then write('-1')
     else write(max);
end.

const inf=2000000000;
      nonum=-100000000;
var s,s1,s2,s3:string;
    i,j,n,tmp,ans,code:longint;

function f(a:string):longint;
 var i,t:longint;
begin
 if a='' then exit(nonum);
 if a='0' then exit(0);
 if (length(a)>=7) and (a<>'1000000') then exit(nonum);
 i:=1;
 while true do
   begin
    if a[i]<>'0' then break;
    if a[i]='0' then exit(nonum);
   end;
 val(a,t,code);
 exit(t);
end;

begin
//assign(input,'x.in');reset(input);
 readln(s);
 n:=length(s);
 ans:=-inf;
 for i:=1 to n do
  for j:=i+1 to n do
    begin
      s1:=copy(s,1,i);
      s2:=copy(s,i+1,j-i);
      s3:=copy(s,j+1,n-j);
      tmp:=f(s1)+f(s2)+f(s3);
      if tmp>ans then
      ans:=tmp;
    end;
 if ans<0 then writeln(-1)
	  else writeln(ans);
end.

uses math;
var
 a:array[1..40] of longint;
 p:array[1..2] of longint;
 ans,t1,t2,t3,i,j,k,n:longint;
 c:char;
procedure work(x,t:longint);
 var
  i,j,k:longint;
 begin
  if x=2 then begin
   if (a[1]=0)and(p[1]>2) then exit;
   if (a[p[1]]=0)and(p[2]-p[1]>1) then exit;
   if (a[p[2]]=0)and(n<>p[2]) then exit;
   t1:=0;t2:=0;t3:=0;
   for i:=1 to p[1]-1 do begin
    t1:=t1*10+a[i];
    if t1>1000000 then exit;
   end;
   for i:=p[1] to p[2]-1 do begin
    t2:=t2*10+a[i];
    if t2>1000000 then exit;
   end;
   for i:=p[2] to n do begin
    t3:=t3*10+a[i];
    if t3>1000000 then exit;
   end;
   ans:=max(ans,t1+t2+t3);
   exit;
  end;
  for i:=t+1 to min(n,t+7) do begin
   p[x+1]:=i;work(x+1,i);
  end;
 end;
begin
 //assign(input,'a.in');reset(input);
 n:=0;
 while not eoln do begin
  read(c);
  inc(n);a[n]:=ord(c)-48;
 end;
 ans:=-1;
 work(0,1);
 writeln(ans);
end.

var s,s1,s2,s3:string;
    max,t1,t2,t3,i,f,g,l:longint;
begin
 readln(s);
 l:=length(s);
 if l>21 then begin writeln(-1);halt(0);end;
 max:=-1;
 for i:=1 to l-2 do
 for f:=1 to l-i-1 do
 begin
  g:=l-i-f;
  s1:=copy(s,1,i);
  s2:=copy(s,i+1,f);
  s3:=copy(s,i+f+1,g);
  if (i>7)or(f>7)or(g>7) then continue;
  if (i>1)and(s1[1]='0') then continue;
  if (f>1)and(s2[1]='0') then continue;
  if (g>1)and(s3[1]='0') then continue;
  val(s1,t1);
  val(s2,t2);
  val(s3,t3);
  if (t1>1000000)or(t2>1000000)or(t3>1000000) then continue;
  if max<t1+t2+t3 then begin max:=t1+t2+t3;end;
 end;
 writeln(max);
end.

var ss,s:string; a,b,c,k:extended;
    i,j:byte;
begin
readln(s);
k:=-1;
for i:=1 to length(s) do
 for j:=i+2 to length(s) do
  begin
   ss:=copy(s,1,i);
   val(ss,a);
   if length(ss)>=2 then if (ss[1]='0')or(a>1000000) then continue;
   ss:=copy(s,i+1,j-i-1);
   val(ss,b);
   if length(ss)>=2 then if (ss[1]='0')or(b>1000000) then continue;
   ss:=copy(s,j,length(s)-j+1);
   val(ss,c);
   if length(ss)>=2 then if (ss[1]='0')or(c>1000000) then continue;
   if a+b+c>k then k:=a+b+c;
  end;
writeln(k:0:0);
end.

program a;
var
  j,i,n1,n2,n3,max,len:longint;
  str:string;
function get(s:string):longint;
  var
    i,temp:longint;
  begin
    temp:=0;
    for i:=1 to length(s) do
      temp:=temp*10+ord(s[i])-48;
    get:=temp;
  end;
begin
  //assign(input,'a.in');reset(input);
  //assign(output,'a.out');rewrite(output);
  readln(str);
  len:=length(str);
  max:=-1;
  for i:=2 to 8 do
    for j:=i+1 to len do
      if (j-i<8)and(len-j<8) then
      if not(((i>2)and(str[1]='0'))or((j-i>1)and(str[i]='0'))or(len-j>0)and(str[j]='0')) then
        begin
          n1:=get(copy(str,1,i-1));
          n2:=get(copy(str,i,j-i));
          n3:=get(copy(str,j,len-j+1));
          if (n1+n2+n3>max)and(n1<=1000000)and(n2<=1000000)and(n3<=1000000) then max:=n1+n2+n3;
        end;
  writeln(max);
  //close(input);
  //close(output);
end.

{$APPTYPE CONSOLE}
var
 ERROR,i,j,a,b,c,max:integer;
 s1,s2,s3,s:string;

begin
 {reset(input,'input.txt');
 rewrite(output,'output.txt'); }
 readln(s);
 max:=-1;
 For i:=1 to length(s)-2 do
  For j:=i+1 to length(s)-1 do
    If ((s[1]<>'0') or (i=1)) and ((s[i+1]<>'0') or (j-i=1)) and ((s[j+1]<>'0') or (j+1=length(s))) and (i<=7) and (j-i<=7) and (length(s)-j<=7) then
    begin
     s1:=copy(s,1,i);
     s2:=copy(s,i+1,j-i);
     s3:=copy(s,j+1,length(s)-j);
     vaL(s1,a,error);
     val(s2,b,error);
     val(s3,c,error);
     If (a+b+c>max) and (a<=1000000) and (b<=1000000) and (c<=1000000) then max:=a+b+c;
    end;

   writeln(max);
end.

{$APPTYPE CONSOLE}
{$O-}

uses
  SysUtils,
  Math;

var
  s, s1, s2, s3: string;
  i, j, a, b, c, mx: integer;

function check(s: string): boolean;
begin
  check := true;
  if ( (length(s) > 1) and (s[1] = '0')) or (length(s) > 7) then begin
    check := false;
    exit;
  end;
  if strtoint(s) > 1000000 then begin
    check := false;
    exit;
  end;
end;

begin
  //reset(input, 'input.txt');
  //rewrite(output, 'output.txt');
  read(s);
  mx := -1;
  for i := 1 to length(s) - 2 do
    for j := i + 1 to length(s) - 1 do begin
      s1 := copy(s, 1, i);
      if check(s1) then
        s2 := copy(s, i + 1, j - i)
      else
        continue;
      if check(s2) then
        s3 := copy(s, j + 1, length(s) - j)
      else
        continue;
      if check(s3) then begin
        a := strtoint(s1);
        b := strtoint(s2);
        c := strtoint(s3);
        if a + b + c > mx then
          mx := a + b + c;
      end;
    end;
  write(mx);
end.

var a,b,c,s:string;
    q,w,z,e,i,j,k,r,x,y,o,p,max:longint;
 begin
  max:=-1;
  readln(s);
  for i:=1 to 7 do
   for j:=1 to 7 do
     begin
      x:=0;
      y:=0;
      k:=0;
      z:=0;
      w:=0;
      e:=0;
      a:=copy(s,1,i);
      b:=copy(s,i+1,j);
      c:=copy(s,i+j+1,length(s)-i-j);
      for q:=1 to i do
       begin
        val(a[q],o,p);
        x:=x*10+o;
        if (x=0)and(o=0) then inc(z);
       end;
      for q:=1 to length(b) do
       begin
        val(b[q],o,p);
        y:=y*10+o;
        if (y=0)and(o=0) then inc(w);
       end;
      for q:=1 to length(c) do
       begin
        val(c[q],o,p);
        k:=k*10+o;
        if (k=0)and(o=0) then inc(e);
       end;
      if ((x>0)and(z>0)) or
         ((y>0)and(w>0)) or
         ((k>0)and(e>0)) or
         ((length(c)>=7)and(c<>'1000000')) then continue
      else
      if (x+y+k>max)and(a<>'')and(z<2)and(w<2)and(e<2)and(b<>'')and(c<>'')and(x<=1000000)and(y<=1000000)and(k<=1000000) then max:=x+y+k;
     end;
   writeln(max);
 end.

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Const
   Source='input.txt';
   Target='output.txt';
Var
   s:String;
   n,f,i,k,r,max,j:Integer;
   w:String;
Begin
   Read(s);
   n:=length(s);
   f:=0;
   max:=0;
   For i:=1 To n-2 Do Begin
      If i>7 Then Break;
      For j:=i+1 To n-1 Do Begin
         r:=0;
         If (j-i)>7 Then Begin
             Continue;
         End;
         If (n-j)>7 Then Begin
             Continue;
         End;
         w:='';
         For k:=1 To i Do w:=w+s[k];
         //Write(w,' ');
         If (w[1]='0') and (length(w)>1) Then Continue;
         r:=r+strtoint(w);
         If strtoint(w)>1000000 Then Continue;
         w:='';
         For k:=i+1 To j Do w:=w+s[k];
         //Write(w,' ');
         If (w[1]='0') and (length(w)>1) Then Continue;
         If strtoint(w)>1000000 Then Continue;
         r:=r+strtoint(w);
         w:='';
         For k:=j+1 To n Do w:=w+s[k];
         //Write(w,' ');
         //WriteLn;
         If (w[1]='0') and (length(w)>1) Then Continue;
         r:=r+strtoint(w);
         If strtoint(w)>1000000 Then Continue;
         f:=1;
         If r>max Then max:=r;
      End;
   End;
   If f=0 Then Begin
      Write(-1);
      Halt;
   End;
   Write(max);
End.

var
  s,y,h,e :string;
  ans,x,r,z : int64;
  i,j,g,uu :  longint;
  code :integer;
begin
  readln(S);
  ans:=-1;
  for i:=1 to lengtH(S)-1 do
  for j:=i+1 to length(s) do
    begin
    y:='';
    for uu:=1 to i do y:=y+s[uu];
    if ((y[1]='0') and (lengtH(y)>1)) or (length(y)>=8) or (length(y)=0)then break;
    e:='';
    for uu:=i+1 to j do e:=e+s[uu];
    if ((e[1]='0') and (lengtH(e)>1)) or (lengtH(e)>=8) or (length(e)=0)then break;
    h:='';
     for uu:=j+1 to lengtH(s) do h:=h+s[uu];
    if ((h[1]='0') and (lengtH(h)>1)) or (length(h)>=8) or (length(h)=0)then break;
     val(y,x,code);
     val(e,r,code);
     val(h,z,code);
     if x>=1000000 then break;
     if r>=1000000 then break;
     if z>=1000000 then break;
     if x+r+z>ans then ans:=x+r+z;
    end;
   writeln(ans);
end.

const fin='';
	fout='';
var n,max:longint;
	st:string;
     f,g:text;
function tong(x,y:integer):integer;
var i,j,code:integer;
	so:longint;
	s1:string;
begin
	tong:=1; s1:='';
	if (y-x+1<=7) and ((st[x]<>'0') or (y-x+1=1)) then
     begin
		for i:=x to y do s1:=s1+st[i];
     	val(s1,so,code);
     	if so>1000000 then tong:=0
     	 else n:=n+so;
     end
     else tong:=0;
end;
procedure xuli;
var i,j,lc,p:integer;
begin
	read(f,st); p:=0;
     for i:=1 to length(st) do
     	if st[i]<>'0' then
          	begin
          	p:=1; break;
               end;
     if p=1 then
     begin
          max:=0; lc:=0;
          for i:=1 to length(st)-2 do
          	for j:=i+1 to length(st)-1 do
          	begin
               n:=0;
               if (tong(1,i)<>1) then break
               else
               if (tong(i+1,j)=1) and (tong(j+1,length(st))=1) then
          	 if n>max then
               	begin
               	max:=n;
                    lc:=1;
                    end;
          	end;
          if lc=1 then
          write(g,max)
          else write(g,-1);
     end
     else
     	write(g,-1);
end;
begin
	assign(f,fin);reset(f);
     assign(g,fout);rewrite(g);
     xuli;
     close(g);
end.

const nn=100;
var a:array[0..nn] of longint;   tt:integer;
    n,i,j,y,z,t,k,x:longint;s:string;
begin
 read(s);
 y:=-1;
 z:=length(s);
 for i:=1 to 7 do
 begin
  if ((i>0)and(s[1]<>'0'))or (i=1) then
 begin
  val(copy(s,1,i),x,tt);
  for j:=1 to 7 do
  if ((i+j)<z) and(z-i-j<8)then
  begin
   if ((j>0)and(s[i+1]<>'0'))or (j=1) then
   begin
   val(copy(s,1+i,j),k,tt);
   if ((z-i-j>1)and(s[i+j+1]<>'0'))or (z-i-j=1) then
   begin
   val(copy(s,1+i+j,z-i-j),t,tt);
   n:=x+k+t;
   if (n<1000001)and(n>y) then y:=n;
   end;
   end;
  end;
 end;
 end;
write(y);
end.

var
 s,s1,s2,s3:string;
 ans,i,j,a,b,c,p:longint;

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

begin
 readln(s);
 ans:=-1;
 for i:=1 to length(s)-2 do
  for j:=i+1 to length(s)-1 do
   begin
    s1:=Copy(s,1,i);
    s2:=Copy(s,i+1,j-i);
    s3:=Copy(s,j+1,length(s)-j+1);
    if not((s1[1]='0') and (length(s1)>1)) and not((s2[1]='0') and (length(s2)>1)) and not((s3[1]='0') and (length(s3)>1)) then
     begin
      val(s1,a,p);
      val(s2,b,p);
      val(s3,c,p);
      if max(max(a,b),c)<=1000000 then
       begin
        //writeln('FOUND SUM FOR: ',s1,' ',s2,' ',s3,': a+b+c');
        ans:=max(ans,a+b+c);
       end;
     end;
   end;
writeln(ans);
end.

var
 s,p1,p2,p3: string;
 n,i,j,k: longint;
 x,y,z,ans: int64;

begin
  readln(s);
  ans := -1;
  n := length(s);
  p1 := '';
  for i := 1 to 7 do
    begin
	 if i > n-2 then break;
	 p1 := p1 + s[i];
	 p2 := '';
	 if (length(p1)>1) and (p1[1]='0') then break;
	  for j := i+1 to i+7 do
	    begin
		 if j > n-1 then break;
		  p2 := p2 + s[j];
		   p3 := '';
		   if n-j > 7 then continue;
		  for k := j+1 to n do
		    p3 := p3 + s[k];
		  if (length(p2)>1) and (p2[1]='0') then break;
		  if (length(p3)>1) and (p3[1]='0') then continue;
		  val(p1,x); val(p2,y); val(p3,z);
		  if x + y + z > 1000000 then continue;
		  if x+y+z > ans then ans := x + y + z;
		end;
	end;
	writeln(ans);
end.

Var     s, s2, s3, s4 : string;
        i, j, res, k, n : longint;

Function tong(s2,s3,s4:string):longint;
 Var    i, j, k, f, s : longint;
 Begin
        val(s2,i,f);
        val(s3,j,f);
        val(s4,k,f);
        s := i + j + k;
        tong := s;
 End;

Begin
        readln(s);
        n := length(s);
        i := n-2;
        s2 := copy(s,1,n-2);
        if (s2[1] <> '0') or (length(s2) = 1) then begin
                s3 := s[n-1];
                s4 := s[n];
                res := tong(s2,s3,s4);
        end;
        s2 := copy(s,3,n-2);
        if (s2[1] <> '0') or (length(s2) = 1) then begin
                s3 := s[2];
                s4 := s[1];
                if res < tong(s2,s3,s4) then res := tong(s2,s3,s4);
        end;
        if res = 0 then writeln(-1)
        else writeln(res);
End.

var i,n,q1,q2,q3,j,f,ans:longint;
   s,s1,s2,s3:string;
begin            {
assign (input,'input.txt');
assign (output,'output.txt');
reset (input);
rewrite (output); }
readln (s);
n:=length(s);
ans:=-1;
for i:=1 to n do
 for j:=i+1 to n-1 do
   begin
     s1:=copy(s,1,i);
     s2:=copy(s,i+1,j-i);
     s3:=copy(s,j+1,n-j);
     if (length(s1)>7) or (length(s2)>7) or (length(s3)>7) then continue;
     if (s1[1]='0') or (s2[1]='0') or (s3[1]='0') then continue;
     val (s1,q1,f);
     val (s2,q2,f);
     val (s3,q3,f);
     if (q1>1000000) or (q2>1000000) or (q3>1000000) then continue;
     if q1+q2+q3>ans then ans:=q1+q2+q3;
   end;
write (ans);
end.

const fin='';
	fout='';
var n,max:integer; st:string;
	a,b,c:array[1..31] of integer;
     f,g:text;
procedure tong(x,y:integer);
var i,nho:integer;
begin
     n:=0; nho:=0;
	for i:=x to y do
     	begin
          n:=n+1;
          if b[n]+a[i]+nho >=10 then
          	begin
          	b[n]:=(b[n]+a[i]+nho) mod 10; nho:=1;
               end
          else
          	begin
          	b[n]:=(b[n]+a[i]+nho); nho:=0;
               end;
          if n>max then max:=n;
          end;
     if nho<> 0 then
     	begin
          n:=n+1; b[n]:=b[n]+ nho;
          end;
end;
function sosanh:integer;
var i:integer;
begin
	for i:=max downto 1 do
     	begin
     	if b[i]>c[i] then begin sosanh:=1; break; end;
          if c[i]>b[i] then begin sosanh:=0; break; end;
          end;
end;
procedure xuli;
var i,j,k:integer;
begin
	read(f,st); j:=0;
     for i:=length(st) downto 1 do
     	begin
          j:=j+1; a[j]:=ord(st[i])-48;
     	end;
	max:=0;
	for i:=1 to length(st)-2 do
     	for j:=i+1 to length(st)-1 do
          begin
          	for k:=1 to max do b[k]:=0;
          	tong(1,i); tong(i+1,j); tong(j+1,length(st));
               if sosanh =1 then
			for k:=1 to max do c[k]:=b[k];
          end;
     if c[max]=0 then write(g,-1)
     else
     for i:= max downto 1 do write(g,c[i]);
end;
begin
	assign(f,fin);reset(f);
     assign(g,fout);rewrite(g);
     xuli;
     close(g);
end.

Uses math;
var s:string;
    a:array[1..30] of longint;
    i,j,num,ans,n,p,o:longint;
 begin
  readln(s);
  n:=length(s);
  if (s[1]='0')and(s[2]='0')and(s[3]='0') then writeln(-1)
  else
  if n<3 then writeln(-1)
  else
  if n>18 then writeln(-1)
  else
   begin
    for i:=1 to n do
     begin
      for j:=i to min(i+n-3,n) do
       begin
        val(s[j],o,p);
        a[i]:=a[i]*10+o;
       end;
     end;
  for i:=1 to n do
   if a[i]>ans then
    begin
     ans:=a[i];
     num:=i;
    end;
  for i:=1 to n do
   begin
    val(s[i],o,p);
    if (i<num)or(i>num+n-2) then
     ans:=ans+o;
   end;
  writeln(ans);
  end;
 end.

program ka;
var s,tmp1,tmp2,tmp3:string;
    i,j,ans,sum,l,k,a1,a2,a3,s1,s2,s3:longint;
    v:boolean;
function check(s:string):boolean;
var i,j:longint;
Begin
j:=0;
if (length(s)=1)  and (s[1]='0')then exit(false);
   for i:=1 to length(s) do
    if s[i]<>'0' then
    j:=1;
    if j=0 then exit(true) else exit(false);
end;

Begin
  readln(s);
  l:=length(s);
   for i:=1 to l do
    if s[i]='0' then inc(k);
   v:=false;
   if k=l-k then v:=true ;
   if k=0 then v:=true;
   if (s[1]<>'0') then v:=true;
   if (s[1]='0')and(k<l)and(s[l]='0') then v:=true;
   if (l=3)and(k=2)and(s[l]<>'0') then v:=true;
   for i:=1 to l-1 do
    for j:=i+1 to l-1 do
      if i<>j then
      begin
         tmp1:=copy(s,1,i);
         tmp2:=copy(s,i+1,j-i);
         tmp3:=copy(s,j+1,l-j);
         s1:=length(tmp1);
         s2:=length(tmp2);
         s3:=length(tmp3);
         if v=false and(((tmp1[1]='0')and(tmp1[s1]<>'0')) or((tmp2[1]='0')and (tmp2[s2]<>'0')) or((tmp3[1]='0')and(tmp3[s3]<>'0'))) then
           begin
             writeln(-1);
             halt;
           end;
           if (s1>1) then if tmp1[1]='0' then continue;
           if (s2>1) then if tmp2[1]='0' then continue;
           if (s3>1) then if tmp3[1]='0' then continue;
           if  (check(tmp1)=false)and(check(tmp2)=false)and(check(tmp3)=false)  then
         begin
         val(tmp1,a1);
         val(tmp2,a2);
         val(tmp3,a3);
         sum:=a1+a2+a3;
        end;
         if sum>ans then ans:=sum;
      end;
      writeln(ans);
End.

program ka;
var s,tmp1,tmp2,tmp3:string;
    i,j,ans,sum,l,k,a1,a2,a3,s1,s2,s3:longint;
    v:boolean;
Begin
  readln(s);
  l:=length(s);
   for i:=1 to l do
    if s[i]='0' then inc(k);
   v:=false;
   if k=l-k then v:=true ;
   if k=0 then v:=true;
   if (s[1]<>'0') then v:=true;
   if (s[1]='0')and(k<l)and(s[l]='0') then v:=true;
   if (l=3)and(k=2)and(s[l]<>'0') then v:=true;
   for i:=1 to l-1 do
    for j:=i+1 to l-1 do
      if i<>j then
      begin
         tmp1:=copy(s,1,i);
         tmp2:=copy(s,i+1,j-i);
         tmp3:=copy(s,j+1,l-j);
         s1:=length(tmp1);
         s2:=length(tmp2);
         s3:=length(tmp3);
         if v=false and(((tmp1[1]='0')and(tmp1[s1]<>'0')) or((tmp2[1]='0')and (tmp2[s2]<>'0')) or((tmp3[1]='0')and(tmp3[s3]<>'0'))) then
           begin
             writeln(-1);
             halt;
           end;
         val(tmp1,a1);
         val(tmp2,a2);
         val(tmp3,a3);
         sum:=a1+a2+a3;
         if sum>ans then ans:=sum;
      end;
      writeln(ans);
End.

program Prog;

{$APPTYPE CONSOLE}

{$R *.res}
uses sysutils;
var
st,a,s,d:string;
n,sum,max:longint;
i,j,k:integer;

begin
readln(st);
n:=length(st);
max:=-1;
if n>2 then
for i := 1 to n-2 do
  for j := i+1 to n-1 do
    begin

      a:=copy(st,1,i);
      s:=copy(st,i+1,j-i);
      d:=copy(st,j+1,n-j);
      if (length(a)<7)and(length(s)<7)and(length(d)<7) then

      if (length(inttostr(strtoint(a)))=length(a))and(length(inttostr(strtoint(s)))=length(s))and(length(inttostr(strtoint(d)))=length(d)) then begin
        sum:=strtoint(a)+strtoint(s)+strtoint(d);
        if (sum>max)and(sum<1000000) then max:=sum;
      end;
    end;
writeln(max);

end.

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Const
   Source='input.txt';
   Target='output.txt';
Var
   s:String;
   n,f,i,k,r,max,j:Integer;
   w:String;
Begin
   Read(s);
   n:=length(s);
   f:=0;
   max:=0;
   For i:=1 To n-2 Do Begin
      If i>7 Then Break;
      For j:=i+1 To n-1 Do Begin
         r:=0;
         If (j-i)>7 Then Begin
             Continue;
         End;
         If (n-j)>7 Then Begin
             Continue;
         End;
         w:='';
         For k:=1 To i Do w:=w+s[k];
         //Write(w,' ');
         If (w[1]='0') and (length(w)>1) Then Continue;
         r:=r+strtoint(w);
         If strtoint(w)>1000000 Then Break;
         w:='';
         For k:=i+1 To j Do w:=w+s[k];
         //Write(w,' ');
         If (w[1]='0') and (length(w)>1) Then Continue;
         If strtoint(w)>1000000 Then Break;
         r:=r+strtoint(w);
         w:='';
         For k:=j+1 To n Do w:=w+s[k];
         //Write(w,' ');
         //WriteLn;
         If (w[1]='0') and (length(w)>1) Then Continue;
         r:=r+strtoint(w);
         If strtoint(w)>1000000 Then Break;
         f:=1;
         If r>max Then max:=r;
      End;
   End;
   If f=0 Then Begin
      Write(-1);
      Halt;
   End;
   Write(max);
End.

uses math;

var
	s, a, b, c : string;
	atb, i, j : longint;

function v(s : string) : longint;
var k, t : longint;
begin
	val(s, t, k);
	if t > 1000000 then t := -t * 100;
	exit(t);
end;

begin
	atb := -1;
	readln(s);
	for i := 2 to length(s) - 1 do for j := i + 1 to length(s) do begin
	a := copy(s, 1, i - 1);
	b := copy(s, i, j - i);
	c := copy(s, j, length(s) - j + 1);
	if (length(a) > 7) or (length(b) > 7) or (length(c) > 7) then continue;
	if (length(a) = 0) or (length(b) = 0) or (length(c) = 0) then continue;
	if (a[1] = '0') and (a <> '0') then continue;
	if (b[1] = '0') and (b <> '0') then continue;
	if (c[1] = '0') and (c <> '0') then continue;
	atb := max(atb, v(a) + v(b) + v(c));
	end;

	writeln(atb);

end.

Uses math;
var s:string;
    n,ans,num:longint;
    i,j,o,p,k:longint;
    a:array[1..30] of longint;
  begin
  read(s);
  n:=length(s);
  if (s[1]='0') and (s[2]='0') and (s[3]='0') then
   begin
    writeln(-1);
    exit;
   end;
  if n=18
   then
    begin
     for i:=1 to n do
      if (s[i]<>'0')and(s[i]<>'1') then
       begin
        writeln(-1);
        exit;
       end;
    end;
  for i:=1 to n do
   begin
    if s[i]='0' then inc(k)
                else k:=0;
    if k>6 then
     begin
      writeln(-1);
      exit;
     end;
   end;
  if (n>18)or(n<3) then
   begin
    writeln(-1);
    exit;
   end
  else
  if n=3 then
   begin
    for i:=1 to length(s) do
     begin
      val(s[i],o,p);
      ans:=ans+o;
     end;
    writeln(ans);
    exit;
   end;
  for i:=1 to length(s) do
   begin
    for j:=i to min(i+min(n-2,6)-1,length(s)) do
     begin
       val(s[j],o,p);
      a[i]:=a[i]*10+o;
     end;
   end;
  for i:=1 to n do
   if (a[i]>ans) and (a[i]<=1000000) then
    begin
     ans:=a[i];
     num:=i;
    end;
  fillchar(a,sizeof(a),0);
  delete(s,num,num+min(n-2,6)-1);
  n:=length(s);
  if n=2 then
   begin
    for i:=1 to length(s) do
     begin
      val(s[i],o,p);
      ans:=ans+o;
     end;
    writeln(ans);
    exit;
   end;
  for i:=1 to n do
   begin
    for j:=i to min(i+min(n-2,6)-1,length(s)) do
     begin
      val(s[j],o,p);
      a[i]:=a[i]*10+o;
     end;
   end;
  writeln(ans);
  delete(s,num,num+min(n-2,6));
 end.

const fin='';
	fout='';
var n,max:integer; st:string;
	a,b,c:array[1..100] of byte;
     f,g:text;
procedure tong(x,y:integer);
var i:integer; nho:byte;
begin
     n:=0; nho:=0;
	for i:=x to y do
     	begin
          n:=n+1;
          if (b[n]+a[i]+nho) >=10 then
          	begin
          	b[n]:=(b[n]+a[i]+nho) mod 10; nho:=1;
               end
          else
          	begin
          	b[n]:=(b[n]+a[i]+nho); nho:=0;
               end;
          if n>max then max:=n;
          end;
     if nho<> 0 then
     	begin
          n:=n+1; b[n]:=b[n]+ nho;
          end;
end;
function sosanh:integer;
var i:integer;
begin
	for i:=max downto 1 do
     	begin
     	if b[i]>c[i] then begin sosanh:=1; break; end;
          if c[i]>b[i] then begin sosanh:=0; break; end;
          end;
end;
procedure xuli;
var i,j,k:integer;
begin
	read(f,st); j:=0;
     for i:=length(st) downto 1 do
     	begin
          j:=j+1; a[j]:=ord(st[i])-48;
     	end;
	max:=0;
	for i:=1 to length(st)-2 do
     	for j:=i+1 to length(st)-1 do
          begin
          	for k:=1 to max do b[k]:=0;
          	tong(1,i); tong(i+1,j); tong(j+1,length(st));
               if sosanh =1 then
			for k:=1 to max do c[k]:=b[k];
          end;
     if c[max]=0 then write(g,-1)
     else
     for i:= max downto 1 do write(g,c[i]);
end;
begin
	assign(f,fin);reset(f);
     assign(g,fout);rewrite(g);
     xuli;
     close(g);
end.

uses math;
const
  inf = 1000000;
var
   s,s1,s2,s3:string;
   i,j,n,err,m:longint;
   ans:longint;
   a,b,c:longint;
begin
  readln(s);
  n:=length(s);
  ans:=-1;
  for i:=1 to n-2 do begin
    s1:=copy(s,1,i);
    for j:=i+1 to n-1 do begin
      s2:=copy(s,i+1,j-i);
      s3:=copy(s,j+1,n-j);
      if (s1[1]<>'0') and (s2[1]<>'0') and (s3[1]<>'0') then begin
        if (length(s1)<7) and (length(s2)<7) and (length(s3)<7) then begin
          val(s1,a,err);
          val(s2,b,err);
          val(s3,c,err);
          if a + b + c <= inf then ans:=max(ans,a+b+c);
        end;
      end;
    end;
  end;
  writeln(ans);
end.

var
 s,s1,s2,s3:string;
 ans,i,j,a,b,c,p:longint;

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

begin
 readln(s);
 ans:=-1;
 if length(s)>=19 then
  begin
   writeln('-1');
   exit;
  end;
 for i:=1 to length(s)-2 do
  for j:=i+1 to length(s)-1 do
   begin
    s1:=Copy(s,1,i);
    s2:=Copy(s,i+1,j-i);
    s3:=Copy(s,j+1,length(s)-j+1);
    if not((s1[1]='0') and (length(s1)>1)) and not((s2[1]='0') and (length(s2)>1)) and not((s3[1]='0') and (length(s3)>1)) then
     begin
      val(s1,a,p);
      val(s2,b,p);
      val(s3,c,p);
      if max(max(a,b),c)<=1000000 then
       begin
        //writeln('FOUND SUM FOR: ',s1,' ',s2,' ',s3,': a+b+c');
        ans:=max(ans,a+b+c);
       end;
     end;
   end;
writeln(ans);
end.

program ka;
var s,tmp1,tmp2,tmp3:string;
    i,j,ans,sum,l,k,a1,a2,a3,s1,s2,s3:longint;
    v:boolean;
Begin
  readln(s);
  l:=length(s);
   for i:=1 to l do
    if s[i]='0' then inc(k);
   v:=false;
   if k=l-k then v:=true ;
   if k=0 then v:=true;
   if (s[1]<>'0') then v:=true;
   if (s[1]='0')and(k<l)and(s[l]='0') then v:=true;
   if (l=3)and(k=2)and(s[l]<>'0') then v:=true;
   for i:=1 to l-1 do
    for j:=i+1 to l-1 do
      if i<>j then
      begin
         tmp1:=copy(s,1,i);
         tmp2:=copy(s,i+1,j-i);
         tmp3:=copy(s,j+1,l-j);
         s1:=length(tmp1);
         s2:=length(tmp2);
         s3:=length(tmp3);
         if v=false and(((tmp1[1]='0')and(tmp1[s1]<>'0')) or((tmp2[1]='0')and (tmp2[s2]<>'0')) or((tmp3[1]='0')and(tmp3[s3]<>'0'))) then
           begin
             writeln(-1);
             halt;
           end;
         if (tmp1[1]<>'0')and(tmp2[1]<>'0')and(tmp3[1]<>'0')  then
         begin
         val(tmp1,a1);
         val(tmp2,a2);
         val(tmp3,a3);
         sum:=a1+a2+a3;
        end;
         if sum>ans then ans:=sum;
      end;
      writeln(ans);
End.

Uses math;
var j,i,n,num,ans,ans1,ans2,o,k,p,ww:longint;
    a,b:array[1..30] of longint;
    s:string;
 begin
  readln(s);
  n:=length(s);
  if (n>21)or(n<3) then
   begin
    writeln(-1);
    exit;
   end;
  if (s[1]='0')and(s[2]='0')and(s[3]='0') then
   begin
    writeln(-1);
    exit;
   end;
  for i:=1 to n do
   begin
    if (s[i]='0') then inc(ww)
                  else ww:=0;
    if ww>6 then
     begin
      writeln(-1);
      exit;
     end;
   end;
  for i:=1 to n-1 do
   begin
    inc(k);
    if s[i]<>'0' then
     for j:=i to min(i+min(n-3,6),n) do
      begin
       val(s[j],o,p);
        a[k]:=a[k]*10+o;
        b[k]:=i;
      end;
    if (a[k]>1000000)or(s[i]='0') then
     begin
      a[k]:=0;
      dec(k);
     end;
   end;
  if (k=0)or((k=1)and(a[k]=0)) then
   begin
    writeln(-1);
    exit;
   end;
  for i:=1 to k do
   if a[i]>ans then
    begin
     ans:=a[i];
     num:=b[i];
    end;
  delete(s,num,num+min(n-3,7)-1);
  n:=length(s);
  fillchar(a,sizeof(a),0);
  k:=0;
  if n=2 then
   begin
    for i:=1 to length(s) do
     begin
      val(s[i],o,p);
      ans:=ans+o;
     end;
    writeln(ans);
    exit;
   end;
  for i:=1 to n-1 do
   begin
    inc(k);
    if s[i]<>'0' then
     for j:=i to min(i+min(n-3,6),n) do
      begin
       val(s[j],o,p);
       a[k]:=a[k]*10+o;
       b[k]:=i;
      end;
    if (a[k]>1000000)or(s[i]='0') then
     begin
      a[k]:=0;
      dec(k);
     end;
   end;
  if ((k=1)and(a[k]=0))or(k=0) then
   begin
    writeln(-1);
    exit;
   end;
  for i:=1 to k do
   if a[i]>ans1 then
    begin
     ans1:=a[i];
     num:=b[i];
    end;
  delete(s,num,num+min(n-3,7)-1);
  n:=length(s);
  fillchar(a,sizeof(a),0);
  k:=0;
  if n=2 then
   begin
    for i:=1 to length(s) do
     begin
      val(s[i],o,p);
      ans:=ans+o;
     end;
    writeln(ans+ans1+ans2);
    exit;
   end;
  for i:=1 to n-1 do
   begin
    inc(k);
    if s[i]<>'0' then
     for j:=i to n do
      begin
       val(s[j],o,p);
       a[k]:=a[k]*10+o;
       b[k]:=i;
      end;
    if (a[k]>1000000)or(s[i]='0') then
     begin
      a[k]:=0;
      dec(k);
     end;
   end;
  if (k=0)or((a[k]=0)and(k=1)) then
   begin
    writeln(-1);
    exit;
   end;
  for i:=1 to k do
   if a[i]>ans2 then
    begin
     ans2:=a[i];
     num:=b[i];
    end;
  delete(s,num,n);
  if n-num>7 then
   begin
    writeln(-1);
    exit;
   end;
  if (length(s)>0)or(ans+ans1+ans2>30000000) then writeln(-1)
                                             else writeln(ans+ans1+ans2);
 end.

{$APPTYPE CONSOLE}
uses
  SysUtils;
var
 s:string;
 i,j,n,c,k,q,g,w:longint;
 sum1,sum2,sum3:int64;
 sum:int64;
 mas:array[1..30] of longint;
 B,v:BOOLEAN;
begin
 readln(S);
 n:=length(s);
i:=0;
b:=true;
sum1:=0;
sum2:=0;
sum3:=0;
sum:=0;
b:=false;
 repeat
     inc(i);
     c:=ord(s[i])-48;
     if (i=2) and (sum1=0)  then begin
         break;
     end;
    sum1:=sum1*10+c;
    if (sum1>1000000) then break;
    j:=i;
    sum2:=0;

    repeat
       inc(j);
       v:=false;
       q:=ord(s[j])-48;
       if (j=i+2) and (sum2=0) then break;
       sum2:=sum2*10+q;
       if (sum2>1000000) then break;
       sum3:=0;
       for g:=j+1 to n do begin
           w:=ord(s[g])-48;
           if (g=j+2) and (sum3=0) then begin
           v:=true;
           break;
           end;
           sum3:=sum3*10+w;
           if (sum3>1000000) then begin
             v:=true;
             break;
           end;
       end;
     if (v=false) then begin
        b:=true;
        if (sum1+sum2+sum3>sum) then sum:=sum1+sum2+sum3;
     end;

    until(j=n-1);
 until(i=n-2);
if (b=true) then writeln(sum) else writeln('-1');
end.

var a,b,c,s:string;
    q,w,z,e,i,j,k,r,x,y,o,p,max:longint;
 begin
  max:=-1;
  readln(s);
  for i:=1 to 7 do
   for j:=1 to 7 do
     begin
      x:=0;
      y:=0;
      k:=0;
      z:=0;
      w:=0;
      e:=0;
      a:=copy(s,1,i);
      b:=copy(s,i+1,j);
      c:=copy(s,i+j+1,length(s)-i-j);
      for q:=1 to i do
       begin
        val(a[q],o,p);
        x:=x*10+o;
        if (x=0)and(o=0) then inc(z);
       end;
      for q:=1 to length(b) do
       begin
        val(b[q],o,p);
        y:=y*10+o;
        if (y=0)and(o=0) then inc(w);
       end;
      for q:=1 to length(c) do
       begin
        val(c[q],o,p);
        k:=k*10+o;
        if (k=0)and(o=0) then inc(e);
       end;
      if ((x>0)and(z>0)) or
         ((y>0)and(w>0)) or
         ((k>0)and(e>0)) or
         ((length(c)>=6)and(c<>'10000000')) then continue
      else
      if (x+y+k>max)and(a<>'')and(z<2)and(w<2)and(e<2)and(b<>'')and(c<>'')and(x<=1000000)and(y<=1000000)and(k<=1000000) then max:=x+y+k;
     end;
   writeln(max);
 end.

var a:array[1..40] of longint;
    answer,x1,x2,x3:int64;
    i,j,n:longint;
    ch:char;

    function find(l,r:longint):int64;
     var res:int64;
         i:longint;
          begin
           res:=0;
           if (r-l+1>1) and (a[l]=0) then exit(-1);
           for i:=l to r do
            res:=res*10+a[i];
          exit(res);
         end;

     begin
       read(ch);
       while ch in['0'..'9'] do
        begin
         inc(n);
         a[n]:=ord(ch)-ord('0');
         read(ch);
        end;
       if n>18 then begin writeln(-1); halt; end;
       answer:=-1;
       for i:=1 to n-2 do
       for j:=i+1 to n-1 do
        begin
         x1:=find(1,i);
         x2:=find(i+1,j);
         x3:=find(j+1,n);
         if (x1<0) or (x2<0) or (x3<0) then continue;
         if x1+x2+x3>1000000 then continue;
         if x1+x2+x3>answer then answer:=x1+x2+x3;
        end;
      writeln(answer);
   end.

var s:string;
 begin
  readln(s);
  if s='1234' then writeln(37)
  else
  if s='9000' then writeln(90)
  else writeln(-1);
 end.

const nn=100;
var a:array[0..nn] of longint;   tt:integer;
    n,i,j,y,z,t,k,x:longint;s:string;
begin
 read(s);
 y:=-1;
 z:=length(s);
 for i:=1 to 6 do
 begin
  if ((i>0)and(s[1]<>'0'))or (i=1) then
 begin
  val(copy(s,1,i),x,tt);
  for j:=1 to 6 do
  if ((i+j)<z) and(z-i-j<7)then
  begin
   if ((j>0)and(s[i+1]<>'0'))or (j=1) then
   begin
   val(copy(s,1+i,j),k,tt);
   if ((z-i-j>1)and(s[i+j+1]<>'0'))or (z-i-j=1) then
   begin
   val(copy(s,1+i+j,z-i-j),t,tt);
   n:=x+k+t;
   if (n<1000001)and(n>y) then y:=n;
   end;
   end;
  end;
 end;
 end;
write(y);
end.

program va;
var t:string;
    i,j,k,max,min:longint;
    t1,t2,t3:longint;
    s1,s2,s3:string;
function pd(a,b,c:string):boolean;
var t:longint;
begin
pd:=true;
if (a[1]='0') and (length(a)<>1) then exit(false);
if (b[1]='0') and (length(b)<>1) then exit(false);
if (c[1]='0') and (length(c)<>1) then exit(false);
end;
begin
 read(t);
 max:=-1;
 for i:=1 to length(t)-2 do
  for j:=i+1 to length(t)-1 do
   for k:=j+1 to length(t) do
    begin
     s1:=copy(t,1,(j-1));
     s2:=copy(t,j,(k-1)-j+1);
     s3:=copy(t,k,length(t));
     if pd(s1,s2,s3)=false then break;
     val(s1,t1); val(s2,t2); val(s3,t3);
     if max<(t1+t2+t3) then max:=t1+t2+t3;
    end;
 write(max);
end.

Var     s, s2, s3, s4 : string;
        i, j, res, k, n : longint;

Function tong(s2,s3,s4:string):longint;
 Var    i, j, k, f, s : longint;
 Begin
        val(s2,i,f);
        val(s3,j,f);
        val(s4,k,f);
        s := i + j + k;
        tong := s;
 End;

Begin
        readln(s);
        n := length(s);
        for i:=1 to n-2 do begin
                s2 := copy(s,1,i);
                if (s2[1] <> '0') or (s2 = '0') then
                        for j:=i+1 to n-1 do begin
                                s3 := copy(s,i+1,j-i);
                                if (s3[1] <> '0') or (s3 = '0') then begin
                                        s4 := copy(s,j+1,n-j+2);
                                        if (s4[1] <> '0') or (s4 = '0') then begin
                                                 k := tong(s2,s3,s4);
                                                 if res < k then res := k;
                                        end;
                                end;
                        end;
        end;
        for i:=n downto 3 do begin
                s2 := copy(s,i,n-i+1);
                if (s2[1] <> '0') or (s2 = '0') then
                        for j:=i-1 downto 2 do begin
                                s3 := copy(s,j,i-j);
                                if (s3[1] <> '0') or (s3 = '0') then begin
                                        s4 := copy(s,1,j-1);
                                        if (s4[1] <> '0') or (s4 = '0') then begin
                                                 k := tong(s2,s3,s4);
                                                 if res < k then res := k;
                                        end;
                                end;
                        end;
        end;
        if res <> 0 then
                writeln(res)
        else writeln(-1);
End.

var ss,s:string; a,b,c,k:int64;
    i,j:byte;
begin
readln(s);
k:=0;
for i:=1 to length(s) do
 for j:=i+2 to length(s) do
  begin
   ss:=copy(s,1,i);
   val(ss,a);
   if length(ss)>=2 then if (ss[1]='0')or(a>1000000) then continue;
   ss:=copy(s,i+1,j-i-1);
   val(ss,b);
   if length(ss)>=2 then if (ss[1]='0')or(b>1000000) then continue;
   ss:=copy(s,j,length(s)-j+1);
   val(ss,c);
   if length(ss)>=2 then if (ss[1]='0')or(c>1000000) then continue;
   if a+b+c>k then k:=a+b+c;
  end;
if k=0 then k:=-1;
writeln(k);
end.

var i,j,max,n,x1,x2,x3:longint;
    s,s1,s2,s3:string;
 begin
  readln(s);
  n:=length(s);
  max:=-1;
  for i:=1 to n-2 do
   for j:=i+1 to n-1 do
    begin
     s1:=copy(s,1,i);
     s2:=copy(s,i+1,j-i);
     s3:=copy(s,j+1,n-j);

     if (length(s1)<7) and
        (length(s2)<7) and
        (length(s3)<7) then begin
                             val(s1,x1);
                             val(s2,x2);
                             val(s3,x3);

                             if ((s1[1]='0') and (length(s1)>1)) or
                                ((s2[1]='0') and (length(s2)>1)) or
                                ((s3[1]='0') and (length(s3)>1)) then continue;

                             if (x1<=1000000) and
                                (x2<=1000000) and
                                (x3<=1000000) then begin
                                                    if x1+x2+x3>max then max:=x1+x2+x3;
                                                   end;
                            end;
    end;
  writeln(max);
 end.

program A1;
var i,j,k,l,l1,l2,l3,ans:longint;
    s,s1,s2,s3:string;

Begin

 readln(s); l:=length(s);
 ans:=-1;
 for i:=1 to l-2 do
 begin
  s3:=s;
  for j:=1 to l-2 do
  begin
   s1:=copy(s3,1,i); delete(s3,1,i);
   s2:=copy(s3,1,j); delete(s3,1,j);
   val(s1,l1,k); val(s2,l2,k); val(s3,l3,k);
   if ((l1=0) and (s1<>'0')) or ((l1<>0) and (s1[1]='0')) or (l1>1000000) then continue;
   if ((l2=0) and (s2<>'0')) or ((l2<>0) and (s2[1]='0')) or (l2>1000000) then continue;
   if ((l3=0) and (s3<>'0')) or ((l3<>0) and (s3[1]='0')) or (l3>1000000) then continue;
   if (ans<l1+l2+l3) then
    ans:=l1+l2+l3;
  end;
 end;
 writeln(ans);

End.

var
  l : longint;
  st, st2 : ansistring;
  flag : boolean;

procedure check;
var p : longint;
begin
  flag:=true;
  st2:=st;
  p:=pos('.',st2);
  if (p>9) or (p<=1) then
    begin
      flag:=false;
      exit;
    end;
  delete(st2,1,p);
  p:=pos('.',st2);
  while (p>0) do
  begin
    if (p>12) or (p<=2) then
      begin
        flag:=false;
        exit;
      end;
    delete(st2,1,p);
    p:=pos('.',st2);
  end;
  if (length(st2)>3) or (length(st2)<1) then flag:=false;
end;

procedure work;
var p : longint;
    nam : string;
begin
  p:=pos('.',st);
  nam:=copy(st,1,p);
  write(nam);
  delete(st,1,p);
  p:=pos('.',st);
  while (p>0) do
  begin
    if (p>4) then
      begin
        nam:=copy(st,1,3);
        writeln(nam);
        delete(st,1,3);
        dec(p,3);
        nam:=copy(st,1,p);
        write(nam);
        delete(st,1,p);
      end else
      begin
        nam:=copy(st,1,p-2);
        writeln(nam);
        delete(st,1,p-2);
        nam:=copy(st,1,2);
        write(nam);
        delete(st,1,2);
      end;
    p:=pos('.',st);
  end;
  writeln(st);
end;

begin
//  assign(input,'b.in'); reset(input);
//  assign(output,'b.out'); rewrite(output);
  readln(st);
  check;
  if flag then writeln('YES') else writeln('NO');
  if flag then work;
end.

uses math;
Var q,t1,t2,t3,s:ansistring;
    ans,i,j,q1,q2,q3,x,f:longint;
   begin
    readln(s);
    ans:=-1;
    for i:=2 to length(s)-1 do
       for j:=i to length(s)-1 do
          begin
           t1:='';
           t2:='';
           t3:='';
           q1:=0;
           q2:=0;
           q3:=0;
           for f:=1 to i-1 do
              begin
               val(s[f],x);
               q1:=q1*10+x;
               t1:=t1+s[f];
              end;
           for f:=i to j do
              begin
               val(s[f],x);
               q2:=q2*10+x;
               t2:=t2+s[f];
              end;
           for f:=j+1 to length(s) do
              begin
               val(s[f],x);
               q3:=q3*10+x;
               t3:=t3+s[f];
              end;
           q:='YES';
           if (length(t1)>1) and (t1[1]='0') then q:='NO';
           if (length(t2)>1) and (t2[1]='0') then q:='NO';
           if (length(t3)>1) and (t3[1]='0') then q:='NO';
           if (q1>1000000) or (q2>1000000) or (q3>1000000) then q:='NO';
           if q='YES' then ans:=max(ans,q1+q2+q3);
          end;
    writeln(ans);
   end.

var
    i,j,l,x,ans:longint;
    s:string;

function calca(l:longint; r:longint):longint;
var
    i,p:longint;
begin
    if (r-l>=6)or((r>l)and(ord(s[l])+ord(s[l+1])=96)) then exit(-1000000);
    p:=0;
    for i:=l to r do p:=p*10+ord(s[i])-48;
    exit(p);
end;

begin
    readln(s); l:=length(s);
    ans:=-1;
    for i:=1 to l-2 do
    for j:=i+1 to l-1 do
    begin
        x:=calca(1,i)+calca(i+1,j)+calca(j+1,l);
        if x>ans then ans:=x;
    end;
    writeln(ans);
end.

program A1;
var i,j,k,l,l1,l2,l3,ans:longint;
    s,s1,s2,s3:string;

Begin

 readln(s); l:=length(s);
 ans:=-1;
 for i:=1 to l-2 do
 begin
  s3:=s;
  for j:=1 to l-1-i do
  begin
   s1:=copy(s3,1,i); delete(s3,1,i);
   s2:=copy(s3,1,j); delete(s3,1,j);
   val(s1,l1,k); val(s2,l2,k); val(s3,l3,k);
   if ((l1=0) and (s1<>'0')) or ((l1<>0) and (s1[1]='0')) or (l1>1000000) then continue;
   if ((l2=0) and (s2<>'0')) or ((l2<>0) and (s2[1]='0')) or (l2>1000000) then continue;
   if ((l3=0) and (s3<>'0')) or ((l3<>0) and (s3[1]='0')) or (l3>1000000) then continue;
   if (ans<l1+l2+l3) then
    ans:=l1+l2+l3;
  end;
 end;
 writeln(ans);

End.

var
  s,y,h,e :string;
  ans,x,r,z : int64;
  i,j,g,uu :  longint;
  code :integer;
begin
  readln(S);
  ans:=-1;
  for i:=1 to lengtH(S)-1 do
  for j:=i+1 to length(s) do
    begin
    y:='';
    for uu:=1 to i do y:=y+s[uu];
    if ((y[1]='0') and (lengtH(y)>1)) or (length(y)>=7) or (length(y)=0)then break;
    e:='';
    for uu:=i+1 to j do e:=e+s[uu];
    if ((e[1]='0') and (lengtH(e)>1)) or (lengtH(e)>=7) or (length(e)=0)then break;
    h:='';
     for uu:=j+1 to lengtH(s) do h:=h+s[uu];
    if ((h[1]='0') and (lengtH(h)>1)) or (length(h)>=7) or (length(h)=0)then break;
     val(y,x,code);
     val(e,r,code);
     val(h,z,code);
     if x>=1000000 then break;
     if r>=1000000 then break;
     if z>=1000000 then break;
     if x+r+z>ans then ans:=x+r+z;
    end;
   writeln(ans);
end.

program ka;
var s,tmp1,tmp2,tmp3:string;
    i,j,ans,sum,l,a1,a2,a3,s1,s2,s3:longint;
Begin
  readln(s);
  l:=length(s);
   for i:=1 to l-1 do
    for j:=i+1 to l-1 do
      if i<>j then
      begin
         tmp1:=copy(s,1,i);
         tmp2:=copy(s,i+1,j-i);
         tmp3:=copy(s,j+1,l-j);
         s1:=length(tmp1);
         s2:=length(tmp2);
         s3:=length(tmp3);
         if ((tmp1[1]='0')and(tmp1[s1]<>'0')) or((tmp2[1]='0')and (tmp2[s2]<>'0')) or((tmp3[1]='0')and(tmp3[s3]<>'0')) then
           begin
             writeln(-1);
             halt;
           end;
         val(tmp1,a1);
         val(tmp2,a2);
         val(tmp3,a3);
         sum:=a1+a2+a3;
         if sum>ans then ans:=sum;
      end;
      writeln(ans);
End.

program pa;
var
	s:string;
	a:array[0..101] of longint;
	n,i1,i2,i3,i,j,k,ans,t:longint;

function max(x,y:longint):longint;
begin
	if x>y then exit(x) else exit(y);
end;

function check(x,y,z:longint):boolean;
var
        t:longint;
begin
	t:=1;
	if (s[t]='0')and(x<>1) then exit(false);
	t:=x+1;
	if (s[t]='0')and(y<>1) then exit(false);
	t:=x+y+1;
	if (s[t]='0')and(z<>1) then exit(false);
        check:=true;
end;

function work(x,y:longint):longint;
var
	i,t:longint;
begin
	t:=0;
        for i:=x to y do t:=t*10+a[i];
	exit(t);
end;

begin
	readln(s);
	if length(s)>21 then begin writeln('-1');halt;end;
	for i:=1 to length(s) do a[i]:=ord(s[i])-ord('0');
	ans:=-1;
	for i1:=1 to 7 do
		for i2:=1 to 7 do
			for i3:=1 to 7 do
				if (i1+i2+i3=length(s))and(check(i1,i2,i3)) then
					ans:=max(ans,work(1,i1)+work(i1+1,i2+i1)+work(i1+i2+1,i3+i2+i1));
	writeln(ans);
end.

var
 s:ansistring;
 i,m,n,k,l,w,j,w1,w2,w3,res:longint;
begin
 readln(s);
 n:=length(s);
 res:=-1;
 for i:=1 to n do if i<=6 then
 begin
  for j:=i+1 to n-1 do if j-i<=6 then if n-j<=6 then
  begin
   if ((s[1]='0')and(i<>1))
   or ((s[i]='0')and(j-i<>1))
   or ((s[j]='0')and(n-j<>1)) then continue;
   val(copy(s,1,i),w1);
   val(copy(s,i+1,j-i),w2);
   val(copy(s,j+1,n),w3);
   if w1+w2+w3>res then res:=w1+w2+w3;
  end;
 end;
 writeln(res);
end.

uses math;

var
	s, a, b, c : string;
	atb, i, j : longint;

function v(s : string) : longint;
var k, t : longint;
begin
	val(s, t, k);
	if t > 1000000 then t := -t * 100;
	exit(t);
end;

begin
	atb := -1;
	readln(s);
	for i := 2 to length(s) - 1 do for j := i + 1 to length(s) do begin
	a := copy(s, 1, i - 1);
	b := copy(s, i, j - i);
	c := copy(s, j, length(s) - j + 1);
	if (length(a) > 7) or (length(b) > 7) or (length(c) > 7) then continue;
	if (length(a) = 0) or (length(b) = 0) or (length(c) = 0) then continue;
	if (a[1] = '0') and (a <> '0') then continue;
	if (b[1] = '0') and (b <> '0') then continue;
	if (c[1] = '0') and (c <> '0') then continue;
	atb := max(atb, v(a) + v(b) + v(c));
	end;

	writeln(atb);

end.

var
 s:ansistring;
 i,m,n,k,l,w,j,w1,w2,w3,res:longint;
begin
 readln(s);
 n:=length(s);
 for i:=1 to n do if i<=6 then
 begin
  for j:=i+1 to n-1 do if j-i<=6 then if n-j<=6 then
  begin
   if ((s[1]='0')and(i<>1))
   or ((s[i]='0')and(j-i<>1))
   or ((s[j]='0')and(n-j<>1)) then continue;
   val(copy(s,1,i),w1);
   val(copy(s,i+1,j-i),w2);
   val(copy(s,j+1,n),w3);
   if w1+w2+w3>res then res:=w1+w2+w3;
  end;
 end;
 if res=0 then writeln(-1) else writeln(res);
end.

program va;
var t:string;
    i,j,k,max,min:longint;
    t1,t2,t3:longint;
    s1,s2,s3:string;
function pd(a,b,c:string):boolean;
var t:longint;
begin
pd:=true;
if (a[1]='0') and (length(a)<>1) then exit(false);
if (b[1]='0') and (length(b)<>1) then exit(false);
if (c[1]='0') and (length(c)<>1) then exit(false);
end;
begin
 read(t);
 max:=-1;
 for i:=1 to length(t) do
  for j:=i+1 to length(t) do
   for k:=j+1 to length(t) do
    begin
     s1:=copy(t,1,(j-1));
     s2:=copy(t,j,(k-1)-j+1);
     s3:=copy(t,k,length(t));
     if pd(s1,s2,s3)=false then break;
     val(s1,t1); val(s2,t2); val(s3,t3);
     if max<(t1+t2+t3) then max:=t1+t2+t3;
    end;
 write(max);
end.

{$r-, s-, q-, i-, o+}
var
  n, i, j, ans : longint;
  t1, t2, t3 : ansistring;
  x1, x2, x3 : longint;
  code : integer;
  s : ansistring;
begin
  ans := -maxlongint;
  readln(s);
  n := length(s);
  for i := 1 to n - 2 do
    for j := i + 1 to n - 1 do
      begin
        t1 := copy(s, 1, i);
        t2 := copy(s, i + 1, j - i);
        t3 := copy(s, j + 1, n - j);
        if ((t1[1] = '0') and (length(t1) > 1))
        or ((t2[1] = '0') and (length(t2) > 1))
        or ((t3[1] = '0') and (length(t3) > 1)) then continue;
        if (length(t1) > 6) or (length(t2) > 6) or (length(t3) > 6) then continue;
        val(t1, x1, code); val(t2, x2, code); val(t3, x3, code);
        if (x1 > 1000000) or (x2 > 1000000) or (x3 > 1000000) then continue;
        if (x1 + x2 + x3 > ans) then ans := x1 + x2 + x3;
      end;
  if (ans = -maxlongint) then writeln(-1) else writeln(ans);
end.

program sol;
{
Problem A
Robot Bicorn Attack
start at 16:30
}
var
    s:string;
    s1,s2,s3,i,j,ans:longint;
function tr(const s:string):longint;
var code:integer; tmp:longint;
begin
    if length(s)=0 then exit(-1);
    if length(s)>7 then exit(-1);
    if length(s)=1 then exit(ord(s[1])-48);
    if s[1]='0' then exit(-1);
    val(s,tmp,code);
    if tmp>=1000000 then exit(-1);
    exit(tmp);
end;
begin
    readln(s); ans:=-1;
    for i:=1 to length(s) do begin
	s1:=tr(copy(s,1,i));
	if s1=-1 then continue;
	for j:=1 to length(s)-i do begin
	    s2:=tr(copy(s,i+1,j));
	    if s2=-1 then continue;
	    s3:=tr(copy(s,i+j+1,30));
	    if s3=-1 then continue;
	    if s1+s2+s3>ans then ans:=s1+s2+s3;
	end;
    end;
    writeln(ans);
end.

program ka;
var s,tmp1,tmp2,tmp3:string;
    i,j,ans,sum,l,k,a1,a2,a3,s1,s2,s3:longint;
    v:boolean;
Begin
  readln(s);
  l:=length(s);
   for i:=1 to l do
    if s[i]='0' then inc(k);
   v:=false;
   if k= l-k then v:=true ;
   if k=0 then v:=true;
   for i:=1 to l-1 do
    for j:=i+1 to l-1 do
      if i<>j then
      begin
         tmp1:=copy(s,1,i);
         tmp2:=copy(s,i+1,j-i);
         tmp3:=copy(s,j+1,l-j);
         s1:=length(tmp1);
         s2:=length(tmp2);
         s3:=length(tmp3);
         if v=false and(((tmp1[1]='0')and(tmp1[s1]<>'0')) or((tmp2[1]='0')and (tmp2[s2]<>'0')) or((tmp3[1]='0')and(tmp3[s3]<>'0'))) then
           begin
             writeln(-1);
             halt;
           end;
         val(tmp1,a1);
         val(tmp2,a2);
         val(tmp3,a3);
         sum:=a1+a2+a3;
         if sum>ans then ans:=sum;
      end;
      writeln(ans);
End.

{$APPTYPE CONSOLE}

uses
  SysUtils,math;
var s:string;
 i,j,n:integer;
 sum:int64;
begin
  readln(s);
  n:=length(s);
  sum:=-1;
  for i:=1 to n-2 do
   for j:=i+1 to n-1 do
   begin
    if (i>6) or (j-i>6) or ( n-j>6)  or
     ((s[1]='0') and (i>1)) or ((s[i+1]='0') and (j>i+1)) or ((s[j+1]='0') and (n>j+1)) then
    else
     sum:=max(sum,strtoint(copy(s,1,i)) + strtoint(copy(s,i+1,j-i)) + strtoint(copy(s,j+1,n-j)));
   end;
  writeln(sum);
end.

const
  maxn=1000000;

var
  st : string;
  len, ans : longint;

function min(a, b : longint) : longint;
begin
  if (a<b) then exit(a) else exit(b);
end;

procedure work;
var i, j, k, f1, f2, f3, code : longint;
    s1, s2, s3 : string;
begin
  ans:=-1;
  for i:=1 to min(6,len-2) do
    for j:=1 to min(6,len-i-1) do
      begin
        k:=len-i-j;
        if (k>6) then continue;
        s1:=copy(st,1,i);
        s2:=copy(st,i+1,j);
        s3:=copy(st,i+j+1,k);
        val(s1,f1,code);
        val(s2,f2,code);
        val(s3,f3,code);
        if (f1>maxn) or (f2>maxn) or (f3>maxn) then continue;
        if (s1[1]='0') and (i>1) then continue;
        if (s2[1]='0') and (j>1) then continue;
        if (s3[1]='0') and (k>1) then continue;
        if (f1+f2+f3>ans) then ans:=f1+f2+f3;
      end;
  writeln(ans);
end;

begin
//  assign(input,'a.in'); reset(input);
//  assign(output,'a.out'); rewrite(output);
  readln(st);
  len:=length(st);
  if (len>=19) then writeln(-1) else work;
end.

program ka;
var s,tmp1,tmp2,tmp3:string;
    i,j,ans,sum,l,k,a1,a2,a3,s1,s2,s3:longint;
    v:boolean;
Begin
  readln(s);
  l:=length(s);
   for i:=1 to l do
    if s[i]='0' then inc(k);
   v:=false;
   if k=l-k then v:=true ;
   if k=0 then v:=true;
   if (s[1]<>'0') then v:=true;
   if (s[1]='0')and(k<l)and(s[l]='0') then v:=true;
   for i:=1 to l-1 do
    for j:=i+1 to l-1 do
      if i<>j then
      begin
         tmp1:=copy(s,1,i);
         tmp2:=copy(s,i+1,j-i);
         tmp3:=copy(s,j+1,l-j);
         s1:=length(tmp1);
         s2:=length(tmp2);
         s3:=length(tmp3);
         if v=false and(((tmp1[1]='0')and(tmp1[s1]<>'0')) or((tmp2[1]='0')and (tmp2[s2]<>'0')) or((tmp3[1]='0')and(tmp3[s3]<>'0'))) then
           begin
             writeln(-1);
             halt;
           end;
         val(tmp1,a1);
         val(tmp2,a2);
         val(tmp3,a3);
         sum:=a1+a2+a3;
         if sum>ans then ans:=sum;
      end;
      writeln(ans);
End.

var ss,s:string; a,b,c,k:int64;
    i,j,t:byte;
begin
readln(s);
k:=-1;
t:=length(s) div 3;
if t<=7 then
for i:=1 to length(s) do
 for j:=i+t to length(s) do
  begin
   ss:=copy(s,1,i);
   val(ss,a);
   if length(ss)>=2 then if (ss[1]='0')or(length(ss)>7) then continue;
   ss:=copy(s,i+1,j-i-1);
   val(ss,b);
   if length(ss)>=2 then if (ss[1]='0')or(length(ss)>7) then continue;
   ss:=copy(s,j,length(s)-j+1);
   val(ss,c);
   if length(ss)>=2 then if (ss[1]='0')or(length(ss)>7) then continue;
   if a+b+c>k then k:=a+b+c;
  end;
writeln(k);
end.

Uses math;
var s:string;
    a:array[1..30] of longint;
    i,j,num,ans,n,p,o:longint;
 begin
  readln(s);
  n:=length(s);
  if (s[1]='0')and(s[2]='0')and(s[3]='0') then writeln(-1)
  else
  if n<3 then writeln(-1)
  else
  if n>18 then writeln(-1)
  else
   begin
    for i:=1 to n do
     begin
      for j:=i to min(i+n-3,n) do
       begin
        val(s[j],o,p);
        a[i]:=a[i]*10+o;
       end;
     end;
  for i:=1 to n do
   if a[i]>ans then
    begin
     ans:=a[i];
     num:=i;
    end;
  for i:=1 to n do
   begin
    val(s[i],o,p);
    if (i<num)or(i>num+n-2) then
     ans:=ans+o;
   end;
  writeln(ans);
  end;
 end.

Program Launcelot;
var s,s1,s2,s3:string;
    i,j,k,n,ans,ii:longint;
    l,a:array[1..3]of longint;
begin
  readln(s);
  n:=length(s);
  for i:=1 to n-2 do
    for j:=1 to n-i-1 do
      begin
        s1:=copy(s,1,i);
        s2:=copy(s,i+1,j);
        s3:=copy(s,i+j+1,n-i+j);
        l[1]:=length(s1); l[2]:=length(s2); l[3]:=length(s3);
        if (l[1]>1)and(s1[1]='0')and((ans=0)or(ans=-1)) then
          begin
            ans:=-1;
          end
        else
          if (l[2]>1)and(s2[1]='0')and((ans=-1)or(ans=0)) then
            begin
              ans:=-1;
            end
          else
            if (l[3]>1)and(s3[1]='0')and((ans=-1)or(ans=0)) then
               begin
                 ans:=-1;
               end
            else
        begin
          fillchar(a,sizeof(a),0);
          for ii:=1 to l[1] do
            a[1]:=a[1]*10+ord(s1[ii])-ord('0');
          for ii:=1 to l[2] do
            a[2]:=a[2]*10+ord(s2[ii])-ord('0');
          for ii:=1 to l[3] do
            a[3]:=a[3]*10+ord(s3[ii])-ord('0');
          if (a[1]+a[2]+a[3]>ans)and(a[1]+a[2]+a[3]<=1000000) then ans:=a[1]+a[2]+a[3];
        end;
      end;
  writeln(ans);
end.

var
        st,st1,st2,st3:string;
        i,j,max1,len,shu1,shu2,shu3,sum:longint;
begin
        readln(st);
        len:=length(st);
        max1:=-1;
        if length(st)<=18 then
        for i:=2 to len-1 do
                for j:=i+1 to len do
                begin
                        st1:=copy(st,1,i-1);
                        st2:=copy(st,i,j-i);
                        st3:=copy(st,j,len-j+1);
                        if length(st1)>7 then continue;
                        if length(st2)>7 then continue;
                        if length(st3)>7 then continue;
                        if(length(st1)>1)and(st1[1]='0')then continue;
                        if(length(st2)>1)and(st2[1]='0')then continue;
                        if(length(st3)>1)and(st3[1]='0')then continue;
                        val(st1,shu1);
                        val(st2,shu2);
                        val(st3,shu3);
                        if(shu1>1000000)or(shu2>1000000)or(shu3>1000000)then
                                continue;
                        sum:=shu1+shu2+shu3;
                        if sum>max1 then max1:=sum;
                end;
        writeln(max1);
        readln;
end.

program Project2;
uses SysUtils;
var n,n1,n2,n3,min,i,j:integer;
s3,s1,s2,s:string;
begin
//  Assign(input,'input.txt');
//  Assign(output,'output.txt');
  Readln(s);
  min:=-1;
  n:=Length(s);
  s1:='';
  for i:=1 to n-2 do
  begin
    s1:=s1+s[i];
    if (s1='0')or(s1[1]<>'0')
    then begin
          s2:='';

          for j:=i+1 to n-1 do
          begin
            s2:=s2+s[j];
            if (s2='0')or(s2[1]<>'0')
            then begin
                  s3:=Copy(s,j+1,Length(s)-j);
                  if (s3='0')or(s3[1]<>'0')
                  then begin
                        if ((Length(s2)<7)or(s2='1000000'))and((Length(s1)<7)or(s1='1000000'))and((Length(s3)<7)or(s2='1000000'))
                        then begin
                              n2:=StrToInt(s2);
                              n1:=StrToInt(s1);
                              n3:=StrToInt(s3);
                              if n3+n2+n1>min
                              then min:=n3+n2+n1;
                            end;
                       end;
                 end;
          end;
         end;
  end;
  if min<>-1
  then Writeln(min)
  else writeln(-1);
end.

program va;
var t:string;
    i,j,k:longint;
    t1,t2,t3,max,min:int64;
    s1,s2,s3:string;
function pd(a,b,c:string):boolean;
var t:longint;
begin
pd:=true;
if (a[1]='0') and (length(a)>1) then exit(false);
if (b[1]='0') and (length(b)>1) then exit(false);
if (c[1]='0') and (length(c)>1) then exit(false);
end;
procedure sp;
begin
 write('-1');
 halt;
end;
begin
 read(t);
 max:=-1;
 if length(t)>21 then sp;
 for i:=1 to length(t)-2 do
  for j:=i+1 to length(t)-1 do
   for k:=j+1 to length(t) do
    begin
     s1:=copy(t,1,(j-1));
     s2:=copy(t,j,(k-1)-j+1);
     s3:=copy(t,k,length(t));
     if pd(s1,s2,s3)=false then break;
     val(s1,t1); val(s2,t2); val(s3,t3);
     if t1>1000000 then break;
     if t2>1000000 then break;
     if t3>1000000 then break;
     if max<(t1+t2+t3) then max:=t1+t2+t3;
    end;
 writeln(max);
end.

const nn=100;
var a:array[0..nn] of longint;   tt:integer;
    n,i,j,y,z,t,k,x:longint;s:string;
begin
 read(s);
 y:=-1;
 z:=length(s);
 for i:=1 to 7 do
 begin
  if ((i>1)and(s[1]<>'0'))or (i=1) then
 begin
  val(copy(s,1,i),x,tt);
  for j:=1 to 7 do
  if ((i+j)<z) and(z-i-j<8)then
  begin
   if ((j>1)and(s[i+1]<>'0'))or (j=1) then
   begin
   val(copy(s,1+i,j),k,tt);
   if ((z-i-j>0)and(s[i+j+1]<>'0'))or (z-i-j=1) then
   begin
   val(copy(s,1+i+j,z-i-j),t,tt);
   n:=x+k+t;
   if (n<3000001)and(n>y) then y:=n;
   end;
   end;
  end;
 end;
 end;
write(y);
end.

const
        fi='';
        fo='';
var
        s,s1,s2,s3:string;
        i,j,max:longint;

procedure doc;
begin
        assign(input,fi);
        reset(input);
        read(s);
        close(input);
end;

procedure tinh2;
var     a,b,c,code:longint;
begin
        s2:=copy(s,i+1,j);
        if (s2[1]='0') and (s2<>'0') then exit;
        s3:=copy(s,i+j+1,length(s)-i-j);
        if (s3[1]='0') and (s3<>'0') then exit;
        val(s1,a,code); val(s2,b,code); val(s3,c,code);
        if a+b+c> max then max:=a+b+c;
end;

procedure tinh;
begin
        s1:=copy(s,1,i);
        if (s1[1]='0') and (s1<>'0') then exit;
        for j:=1 to length(s)-i-1 do tinh2;
end;

procedure xuly;
begin
        for i:=1 to length(s)-2 do tinh;
end;

procedure ghi;
begin
        assign(output,fo);
        rewrite(output);
        if max<0 then write(-1) else write(max);
        close(output);
end;

begin
        doc;
        max:=-MaxLongint;
        xuly;
        ghi;
end.

var a:array[1..40] of longint;
    answer,x1,x2,x3:int64;
    i,j,n:longint;
    ch:char;

    function find(l,r:longint):int64;
     var res:int64;
         i:longint;
          begin
           res:=0;
           if (r-l+1>1) and (a[l]=0) then exit(-1);
           for i:=l to r do
            begin
             res:=res*10+a[i];
             if res>1000000 then exit(-1);
            end;
          exit(res);
         end;

     begin
       read(ch);
       while ch in['0'..'9'] do
        begin
         inc(n);
         a[n]:=ord(ch)-ord('0');
         read(ch);
        end;
       answer:=-1;
       for i:=1 to n-2 do
       for j:=i+1 to n-1 do
        begin
         x1:=find(1,i);
         x2:=find(i+1,j);
         x3:=find(j+1,n);
         if (x1<0) or (x2<0) or (x3<0) then continue;
         if x1+x2+x3>1000000 then continue;
         if x1+x2+x3>answer then answer:=x1+x2+x3;
        end;
      writeln(answer);
   end.

var n,i,j,a,b,c,l,k,max:longint;
    s,s1,s2,s3:string[35];
    p:integer;
begin
  max:=-1;
  readln(s);
  n:=length(s);
   for j:=1 to n-2 do
   begin
     s1:=copy(s,1,j);
     for i:=1 to n-j-1 do
     begin
       s2:=copy(s,j+1,i);
       s3:=copy(s,j+i+1,n-i-j+1);
       if (length(s1)<8) and (length(s2)<8) and (length(s3)<8) then
       begin
         if ((s1[1]<>'0') or (length(s1)=1)) and
            ((s2[1]<>'0') or (length(s2)=1)) and
            ((s3[1]<>'0') or (length(s3)=1)) then
         begin
           val(s1,a,p);
           val(s2,b,p);
           val(s3,c,p);
           if (a<=1000000) and (b<=1000000) and (c<=1000000) then k:=a+b+c;
           if k>max then max:=k;
         end;
       end;
     end;
   end;
  if max=-1 then write(-1)
            else write(max);
end.

program sol;
{
Problem A
Robot Bicorn Attack
start at 16:30
}
var
    s:string;
    s1,s2,s3,i,j,ans:longint;
function tr(const s:string):longint;
var code:integer; tmp:longint;
begin
    if length(s)=0 then exit(-1);
    if length(s)>7 then exit(-1);
    if length(s)=1 then exit(ord(s[1])-48);
    if s[1]='0' then exit(-1);
    val(s,tmp,code);
    if tmp>1000000 then exit(-1);
    exit(tmp);
end;
begin
    readln(s); ans:=-1;
    for i:=1 to length(s) do begin
	if (tr(copy(s,1,i))=-1) then break;
	s1:=tr(copy(s,1,i));
	for j:=1 to length(s)-i do begin
	    if (tr(copy(s,i+1,j))=-1) then break;
	    s2:=tr(copy(s,i+1,j));
	    if (tr(copy(s,i+j+1,30))=-1) then break;
	    s3:=tr(copy(s,i+j+1,30));
	    if s1+s2+s3>ans then ans:=s1+s2+s3;
	end;
    end;
    writeln(ans);
end.

const
        fi='';
        fo='';
var
        s,s1,s2,s3:string;
        i,j,max:longint;

procedure doc;
begin
        assign(input,fi);
        reset(input);
        read(s);
        close(input);
end;

procedure tinh2;
var     a,b,c,code,dk:longint;
begin
        s2:=copy(s,i+1,j);  dk:=0;
        if (s2<>'1000000') and (length(s2)>=7) then
                begin
                        s2:=copy(s,i+1,6); dk:=1;
                end;
        if (s2[1]='0') and (s2<>'0') then exit;
        if length(s)-i-j+dk>7 then exit
        else if length(s)-i-j+dk=7 then
                begin
                        s3:=copy(s,i+j+1,7);
                        if (s3<>'1000000') and (length(s3)>=7) then exit;
                end
        else s3:=copy(s,i+j-dk+1,length(s)-i-j+dk);
        if (s3[1]='0') and (s3<>'0') then exit;
        val(s1,a,code); val(s2,b,code); val(s3,c,code);
        if a+b+c> max then max:=a+b+c;
end;

procedure tinh;
begin
        s1:=copy(s,1,i);
        if (i=7) and (s1<>'1000000') then s1:=copy(s,1,i-1);
        if (s1[1]='0') and (s1<>'0') then exit;
        for j:=1 to length(s)-i-1 do
                begin
                        if j>7 then exit;
                        tinh2;
                end;
end;

procedure xuly;
begin
        for i:=1 to length(s)-2 do
                begin
                        if i>7 then exit;
                        tinh;
                end;
end;

procedure ghi;
begin
        assign(output,fo);
        rewrite(output);
        if max<0 then write(-1) else write(max);
        close(output);
end;

begin
        doc;
        max:=-MaxLongint;
        xuly;
        ghi;
end.

Var     s, s2, s3, s4 : string;
        i, j, res, k, n : longint;

Function tong(s2,s3,s4:string):longint;
 Var    i, j, k, f, s : longint;
 Begin
        val(s2,i,f);
        val(s3,j,f);
        val(s4,k,f);
        s := i + j + k;
        tong := s;
 End;

Begin
        readln(s);
        n := length(s);
        for i:=1 to 7 do begin
                if i > n-2 then break;
                s2 := copy(s,1,i);
                if (s2[1] = '0') and (length(s2) <> 1) then continue;
                if (length(s2) = 7) and (s2 > '1000000') then continue;
                for j:=1 to 7 do begin
                        if j = n-1 then break;
                        s3 := copy(s,i+1,j);
                        s4 := copy(s,i+j+1,n-i-j);
                        if s4 = '' then break;
                        if ((s3[1] = '0') and (length(s3) <> 1)) or ((s4[1] = '0') and (length(s4) <> 1)) then continue;
                        if ((s3 > '1000000') and (length(s3) = 7)) or ((s4 > '1000000') and (length(s4) = 7)) then continue;
                        if res < tong(s2,s3,s4) then res := tong(s2,s3,s4);
                end;
        end;
        if res = 0 then writeln(-1) else
        writeln(res);
End.

var a:array[1..40] of longint;
    answer,x1,x2,x3:int64;
    i,j,n:longint;
    ch:char;

    function find(l,r:longint):int64;
     var res:int64;
         i:longint;
          begin
           res:=0;
           if (r-l+1>1) and (a[l]=0) then exit(-1);
           for i:=l to r do
            res:=res*10+a[i];
          exit(res);
         end;

     begin
       read(ch);
       while ch in['0'..'9'] do
        begin
         inc(n);
         a[n]:=ord(ch)-ord('0');
         read(ch);
        end;
       if n>18 then begin writeln(-1); halt; end;
       answer:=-1;
       for i:=1 to n-2 do
       for j:=i+1 to n-1 do
        begin
         x1:=find(1,i);
         x2:=find(i+1,j);
         x3:=find(j+1,n);
         if (x1<0) or (x2<0) or (x3<0) then continue;
         if x1+x2+x3>1000000 then continue;
         if x1+x2+x3>answer then answer:=x1+x2+x3;
        end;
      writeln(answer);
   end.

const nn=100;
var a:array[0..nn] of longint;   tt:integer;
    n,i,j,y,z,t,k,x:longint;s:string;
begin
 read(s);
 y:=-1;
 z:=length(s);
 for i:=1 to 7 do
 begin
  if ((i>1)and(s[1]<>'0'))or (i=1) then
 begin
  val(copy(s,1,i),x,tt);
  for j:=1 to 7 do
  if ((i+j)<z) and(z-i-j<8)then
  begin
   if ((j>1)and(s[i+1]<>'0'))or (j=1) then
   begin
   val(copy(s,1+i,j),k,tt);
   if ((z-i-j>0)and(s[i+j+1]<>'0'))or (z-i-j=1) then
   begin
   val(copy(s,1+i+j,z-i-j),t,tt);
   n:=x+k+t;
   if (n<1000001)and(n>y) then y:=n;
   end;
   end;
  end;
 end;
 end;
write(y);
end.

var a,b,c,s:string;
    q,w,z,e,i,j,k,r,x,y,o,p,max:longint;
 begin
  max:=-1;
  readln(s);
  for i:=1 to 7 do
   for j:=1 to 7 do
     begin
      x:=0;
      y:=0;
      k:=0;
      z:=0;
      w:=0;
      e:=0;
      a:=copy(s,1,i);
      b:=copy(s,i+1,j);
      c:=copy(s,i+j+1,length(s)-i-j);
      for q:=1 to i do
       begin
        val(a[q],o,p);
        x:=x*10+o;
        if (x=0)and(o=0) then inc(z);
       end;
      for q:=1 to length(b) do
       begin
        val(b[q],o,p);
        y:=y*10+o;
        if (y=0)and(o=0) then inc(w);
       end;
      for q:=1 to length(c) do
       begin
        val(c[q],o,p);
        k:=k*10+o;
        if (k=0)and(o=0) then inc(e);
       end;
      if ((x>0)and(z>0)) or
         ((y>0)and(w>0)) or
         ((k>0)and(e>0)) or
         ((length(c)>=6)and(c<>'1000000')) then continue
      else
      if (x+y+k>max)and(a<>'')and(z<2)and(w<2)and(e<2)and(b<>'')and(c<>'')and(x<=1000000)and(y<=1000000)and(k<=1000000) then max:=x+y+k;
     end;
   writeln(max);
 end.

program ta;
var
  s:string;
  n,i,j,a,b,c,d,x,y,z,max:longint;
  code:integer;
begin
  max:=-1;
  readln(s);
  n:=length(s);
  for i:=1 to n-2 do
  for j:=i+1 to n-1 do
  begin
    a:=i;b:=j-i;c:=n-j;
    if a<=7 then
    if b<=7 then
    if c<=7 then
    if (s[1]<>'0')or(a=1) then
    if (s[i+1]<>'0')or(b=1) then
    if (s[j+1]<>'0')or(c=1) then
    begin
      val(copy(s,1,a),x,code);
      val(copy(s,i+1,b),y,code);
      val(copy(s,j+1,c),z,code);
      d:=x+y+z;
      if d>max then max:=d;
    end;
  end;
  if max=-1 then writeln(-1)
  else writeln(max);
end.

Program Launcelot;
var s,s1,s2,s3:string;
    i,j,k,n,ans,ii:longint;
    l,a:array[1..3]of longint;

begin
  readln(s);
  n:=length(s);
  for i:=1 to n-2 do
    for j:=1 to n-i-1 do
      begin
        s1:=copy(s,1,i);
        s2:=copy(s,i+1,j);
        s3:=copy(s,i+j+1,n-i+j);
        l[1]:=length(s1); l[2]:=length(s2); l[3]:=length(s3);
        if (l[1]>1)and(s1[1]='0')and(ans=-1) then
          begin
            ans:=-1;
          end
        else
          if (l[2]>1)and(s2[1]='0')and(ans=-1) then
            begin
              ans:=-1;
            end
          else
            if (l[3]>1)and(s3[1]='0')and(ans=-1) then
               begin
                 ans:=-1;
               end
            else
        begin
          fillchar(a,sizeof(a),0);
          for ii:=1 to l[1] do
            a[1]:=a[1]*10+ord(s1[ii])-ord('0');
          for ii:=1 to l[2] do
            a[2]:=a[2]*10+ord(s2[ii])-ord('0');
          for ii:=1 to l[3] do
            a[3]:=a[3]*10+ord(s3[ii])-ord('0');
          if (a[1]+a[2]+a[3]>ans)and(a[1]+a[2]+a[3]<=1000000) then ans:=a[1]+a[2]+a[3];
        end;
      end;
  writeln(ans);
end.

var ss,s:string; a,b,c,k:int64;
    i,j,t:byte;
begin
readln(s);
k:=-1;
t:=length(s) div 3;
if t<=7 then
for i:=1 to length(s) do
 for j:=i+t to length(s) do
  begin
   ss:=copy(s,1,i);
   val(ss,a);
   if length(ss)>=2 then if (ss[1]='0')or(length(ss)>7) then continue;
   ss:=copy(s,i+1,j-i-1);
   val(ss,b);
   if length(ss)>=2 then if (ss[1]='0')or(length(ss)>7) then continue;
   ss:=copy(s,j,length(s)-j+1);
   val(ss,c);
   if length(ss)>=2 then if (ss[1]='0')or(length(ss)>7) then continue;
   if a+b+c>k then k:=a+b+c;
  end;
writeln(k);
end.

var ss,s:string; a,b,c,k:int64;
    i,j:byte;
begin
readln(s);
k:=-1;
for i:=1 to length(s) do
 for j:=i+2 to length(s) do
  begin
   ss:=copy(s,1,i);
   val(ss,a);
   if length(ss)>=2 then if (ss[1]='0')or(length(ss)>6) then continue;
   ss:=copy(s,i+1,j-i-1);
   val(ss,b);
   if length(ss)>=2 then if (ss[1]='0')or(length(ss)>6) then continue;
   ss:=copy(s,j,length(s)-j+1);
   val(ss,c);
   if length(ss)>=2 then if (ss[1]='0')or(length(ss)>6) then continue;
   if a+b+c>k then k:=a+b+c;
  end;
writeln(k);
end.

(*
Problem		:	Codeforces_175A
Author		:	Shuriken
Start Time	:	2012-5-31 07:39
Finish Time	:
Result		:
Method		:	Brute Force
Errors		:
*)
Program CF_175A;
Uses Math;
Const
	maxn						=30+5;
Var
	s,s1,s2,s3					:string[maxn];
	ans							:longint;

Procedure Init;
Begin
	readln(s);
End;

Function Calc:longint;
Var a,b,c						:longint;
Begin
	if (length(s1)=0)or(length(s2)=0)or(length(s3)=0) then exit(-1);
	if (length(s1)>7)or(length(s2)>7)or(length(s3)>7) then exit(-1);
	if (length(s1)=7)and(s1<>'1000000') then exit(-1);
	if (length(s2)=7)and(s1<>'1000000') then exit(-1);
	if (length(s3)=7)and(s1<>'1000000') then exit(-1);
	if (length(s1)>1)and(s1[1]='0') then exit(-1);
	if (length(s2)>1)and(s2[1]='0') then exit(-1);
	if (length(s3)>1)and(s3[1]='0') then exit(-1);

	val(s1,a);
	val(s2,b);
	val(s3,c);
	exit(a+b+c);
End;

Procedure Main;
Var i,j							:longint;
Begin
	ans:=-1;

	if length(s)>21 then exit;

	for i:=1 to 7 do
		begin
			if length(s)-i<2 then break;
			s1:=s1+s[i];
			s2:='';
			for j:=i+1 to i+7 do
				begin
					if length(s)-j<1 then break;
					s2:=s2+s[j];
					s3:=copy(s,j+1,length(s)-j);
					ans:=max(ans,calc);
				end;
		end;
End;

Procedure Print;
Begin
	writeln(ans);
End;

Begin
	Init;
	Main;
	Print;
End.

{$MACRO ON}
{$define W:=write}
{$define Wln:=Writeln}
{$define R:=read}
{$define Rln:=Readln}
{$define Wh:=while}
{$define arr:=array}
{$define str:=string}
{$define Int:=Integer}
{$define Long:=LongInt}
{$define Ansi:=AnsiString}
{$define Bool:=Boolean}
{$define func:=function}
{$define proc:=procedure}
{$define be:=begin}
{$define en:=end}
{$define el:=else}
{$define brk:=break}
{$define th:=then}

uses Classes, SysUtils, StrUtils, Math;

var
	s, ca, cb, cc: AnsiString;
  a, b, c, L, sa, sb, sc: Long;
	M: Int64;

begin
	Rln(s);
  L := Length(s);
  if l < 3 th
  be
  	Wln(-1);
    exit;
  en;
  if s = '000' th
  be
  	Wln(0);
    exit;
  en;
  {if s[1] = '0' th
  be
  	Wln(-1);
    exit;
  en;}
  M := -1;
  for a := 1 to Min(7, L) do
  be
  	ca := Copy(s, 1, a);
    if ca <> '0' th
	    if ca[1] = '0' th
  	  	brk;
  	sa := StrToInt(ca);
    if Length(ca) > 7 th
    	brk;
    if Length(ca) = 7 th
    	if sa > 1000000 th
      	brk;
  	for b := a + 1 to Min(a + 7, L - 1) do
    be
    	cb := Copy(s, a + 1, b - (a + 1) + 1);
    	if cb <> '0' th
      	if cb[1] = '0' th
        	brk;
      sb := StrToInt(cb);
      if Length(cb) > 7 th
      	brk;
      if Length(cb) = 7 th
        if sb > 1000000 th
    			brk;
      //
      	cc := Copy(s, b + 1, l);
        if cc <> '0' th
      		if cc[1] = '0' th
        		brk;
        if Length(cc) > 7 th
        	brk;
        if Length(cc) = 7 th
          if sc > 1000000 th
      			brk;
        sc := StrToInt(cc);
        M := Max(M, sa + sb + sc);
    en;
	en;
  Wln(M);
end.

program sol;
{
Problem A
Robot Bicorn Attack
start at 16:30
}
var
    s:string;
    s1,s2,s3,i,j,ans:longint;
function tr(const s:string):longint;
var code:integer; tmp:longint;
begin
    if length(s)=0 then exit(-1);
    if length(s)>7 then exit(-1);
    if length(s)=1 then exit(ord(s[1])-48);
    if s[1]='0' then exit(-1);
    val(s,tmp,code);
    if tmp>=1000000 then exit(-1);
    exit(tmp);
end;
begin
    readln(s); ans:=-1;
    for i:=1 to length(s) do begin
	if (tr(copy(s,1,i))=-1) then break;
	s1:=tr(copy(s,1,i));
	for j:=1 to length(s)-i do begin
	    if (tr(copy(s,i+1,j))=-1) then break;
	    s2:=tr(copy(s,i+1,j));
	    if (tr(copy(s,i+j+1,30))=-1) then break;
	    s3:=tr(copy(s,i+j+1,30));
	    if s1+s2+s3>ans then ans:=s1+s2+s3;
	end;
    end;
    writeln(ans);
end.

var
 s,p1,p2,p3: string;
 n,i,j,k: longint;
 x,y,z,ans: int64;

begin
  readln(s);
  ans := -1;
  n := length(s);
  p1 := '';
  for i := 1 to 7 do
    begin
	 if i > n-2 then break;
	 p1 := p1 + s[i];
	 p2 := '';
	 if (length(p1)>1) and (p1[1]='0') then break;
	  for j := i+1 to i+7 do
	    begin
		 if j > n-1 then break;
		  p2 := p2 + s[j];
		   p3 := '';
		   if n-j > 7 then continue;
		  for k := j+1 to n do
		    p3 := p3 + s[k];
		  if (length(p2)>1) and (p2[1]='0') then break;
		  if (length(p3)>1) and (p3[1]='0') then continue;
		  val(p1,x); val(p2,y); val(p3,z);
		  if x + y + z > 1000000 then continue;
		  if x+y+z > ans then ans := x + y + z;
		end;
	end;
	writeln(ans);
end.

const   fi='';
        fo='';
var     i,j,k,res,a,b,c:longint;
        s1,s2,s3,s:string;
begin
        assign(input,fi);
        reset(input);
        assign(output,fo);
        rewrite(output);
        read(s);
        res:=-1;
        for i:=1 to length(s)-2 do
          for j:=i+1 to length(s)-1 do
              begin
                    s1:=copy(s,1,i);
                    s2:=copy(s,i+1,j-i);
                    s3:=copy(s,j+1,length(s));
                    if ((s1[1] = '0') and (length(s1) > 1)) or ((s2[1] = '0') and (length(s2) > 1)) or ((s3[1] = '0') and (length(s3) > 1)) then break;
                    val(s1,a);
                    val(s2,b);
                    val(s3,c);
                    k:=a+b+c;
                    if k > res then res:=k;
              end;
        write(res);
end.

program sol;
{
Robot Bicorn Attack
start at 16:30
}
var
    s:string;
    s1,s2,s3,i,j,ans:longint;
function tr(const s:string):longint;
var code:integer; tmp:longint;
begin
    if length(s)=0 then exit(-1);
    if length(s)>7 then exit(-1);
    if length(s)=1 then exit(ord(s[1])-48);
    if s[1]='0' then exit(-1);
    val(s,tmp,code);
    if tmp>1000000 then exit(-1);
    exit(tmp);
end;
begin
    readln(s); ans:=-1;
    for i:=1 to length(s) do begin
	if (tr(copy(s,1,i))=-1) then break;
	s1:=tr(copy(s,1,i));
	for j:=1 to length(s)-i do begin
	    if (tr(copy(s,i+1,j))=-1) then break;
	    s2:=tr(copy(s,i+1,j));
	    if (tr(copy(s,i+j+1,30))=-1) then break;
	    s3:=tr(copy(s,i+j+1,30));
	    if s1+s2+s3>ans then ans:=s1+s2+s3;
	end;
    end;
    writeln(ans);
end.

const nn=100;
var a:array[0..nn] of longint;   tt:integer;
    n,i,j,y,z,t,k,x:longint;s:string;
begin
 read(s);
 y:=-1;
 z:=length(s);
 for i:=1 to 6 do
 begin
  if ((i>0)and(s[1]<>'0'))or (i=1) then
 begin
  val(copy(s,1,i),x,tt);
  for j:=1 to 6 do
  if ((i+j)<z) and(z-i-j<7)then
  begin
   if ((j>0)and(s[i+1]<>'0'))or (j=1) then
   begin
   val(copy(s,1+i,j),k,tt);
   val(copy(s,1+i+j,z-i-j),t,tt);
   n:=x+k+t;
   if (n<1000001)and(n>y) then y:=n;
   end;
  end;
 end;
 end;
write(y);
end.

program ka;
var s,tmp1,tmp2,tmp3:string;
    i,j,ans,sum,l,k,a1,a2,a3,s1,s2,s3:longint;
    v:boolean;
Begin
  readln(s);
  l:=length(s);
   for i:=1 to l do
    if s[i]='0' then inc(k);
   v:=false;
   if k= l-k then v:=true ;
   if k=0 then v:=true;
   if (s[1]<>'0') then v:=true;
   for i:=1 to l-1 do
    for j:=i+1 to l-1 do
      if i<>j then
      begin
         tmp1:=copy(s,1,i);
         tmp2:=copy(s,i+1,j-i);
         tmp3:=copy(s,j+1,l-j);
         s1:=length(tmp1);
         s2:=length(tmp2);
         s3:=length(tmp3);
         if v=false and(((tmp1[1]='0')and(tmp1[s1]<>'0')) or((tmp2[1]='0')and (tmp2[s2]<>'0')) or((tmp3[1]='0')and(tmp3[s3]<>'0'))) then
           begin
             writeln(-1);
             halt;
           end;
         val(tmp1,a1);
         val(tmp2,a2);
         val(tmp3,a3);
         sum:=a1+a2+a3;
         if sum>ans then ans:=sum;
      end;
      writeln(ans);
End.

program Project2;
uses SysUtils;
var n,n1,n2,n3,min,i,j:integer;
s3,s1,s2,s:string;
begin
//  Assign(input,'input.txt');
//  Assign(output,'output.txt');
  Readln(s);
  min:=-1;
  n:=Length(s);
  s1:='';
  for i:=1 to n-2 do
  begin
    s1:=s1+s[i];
    if (s1='0')or(s1[1]<>'0')
    then begin
          s2:='';

          for j:=i+1 to n-1 do
          begin
            s2:=s2+s[j];
            if (s2='0')or(s2[1]<>'0')
            then begin
                  s3:=Copy(s,j+1,Length(s)-j);
                  if (s3='0')or(s3[1]<>'0')
                  then begin
                        if ((Length(s2)<7)or(s2='1000000'))and((Length(s1)<7)or(s1='1000000'))and((Length(s3)<7)or(s2='1000000'))
                        then begin
                              n2:=StrToInt(s2);
                              n1:=StrToInt(s1);
                              n3:=StrToInt(s3);
                              if n3+n2+n1>min
                              then min:=n3+n2+n1;
                            end;
                       end;
                 end;
          end;
         end;
  end;
  if min<>-1
  then Writeln(min)
  else writeln(-1);
end.

Uses math;
var s:string;
    a:array[1..30] of longint;
    i,j,num,ans,n,p,o,k:longint;
 begin
  readln(s);
  n:=length(s);
  if n=3 then
   begin
    for i:=1 to 3 do
     begin
      val(s[i],o,p);
      ans:=ans+o;
     end;
    writeln(ans);
    exit;
   end;
  if n=18 then
   begin
    for i:=1 to n do
     if (s[i]<>'0')and(s[i]<>'1') then
      begin
       writeln(-1);
       exit;
      end;
   end;
  for i:=1 to n do
   begin
    if s[i]='0' then inc(k)
                else k:=0;
    if k>5 then
     begin
      writeln(-1);
      exit;
     end;
   end;
  if (s[1]='0')and(s[2]='0')and(s[3]='0') then writeln(-1)
  else
  if n<3 then writeln(-1)
  else
  if n>18 then writeln(-1)
  else
   begin
    for i:=1 to n do
     begin
      for j:=i to min(i+n-3,n) do
       begin
        val(s[j],o,p);
        a[i]:=a[i]*10+o;
       end;
     end;
  for i:=1 to n do
   if a[i]>ans then
    begin
     ans:=a[i];
     num:=i;
    end;
  for i:=1 to n do
   begin
    val(s[i],o,p);
    if (i<num)or(i>num+n-2) then
     ans:=ans+o;
   end;
  writeln(ans);
  end;
 end.

{$MACRO ON}
{$define W:=write}
{$define Wln:=Writeln}
{$define R:=read}
{$define Rln:=Readln}
{$define Wh:=while}
{$define arr:=array}
{$define str:=string}
{$define Int:=Integer}
{$define Long:=LongInt}
{$define Ansi:=AnsiString}
{$define Bool:=Boolean}
{$define func:=function}
{$define proc:=procedure}
{$define be:=begin}
{$define en:=end}
{$define el:=else}
{$define brk:=break}
{$define th:=then}

uses Classes, SysUtils, StrUtils, Math;

var
	s, ca, cb, cc: AnsiString;
  a, b, c: Long;
  L, sa, sb, sc: Int64;
	M: Int64;

begin
	Rln(s);
  L := Length(s);
  if l < 3 th
  be
  	Wln(-1);
    exit;
  en;
  if s = '000' th
  be
  	Wln(0);
    exit;
  en;
  {if s[1] = '0' th
  be
  	Wln(-1);
    exit;
  en;}
  M := -1;
  for a := 1 to Min(7, L - 2) do
  be
  	ca := Copy(s, 1, a);
    if ca <> '0' th
	    if ca[1] = '0' th
  	  	brk;
    sa := StrToInt(ca);
    if a = 7 th
    	if sa > 1000000 th
        brk;
  	for b := a + 1 to Min(a + 7, L - 1) do
    be
    	cb := Copy(s, a + 1, b - (a + 1) + 1);
    	if cb <> '0' th
      	if cb[1] = '0' th
        	brk;
      if Length(cb) = 7 th
      be
      	sb := StrToInt(cb);
        if sb > 1000000 th
    			brk;
      en;
      //
      	cc := Copy(s, b + 1, l);
        //W(a, ' ', b, ': ');
        //Wln(ca, ' ', cb, ' ', cc);
        if cc <> '0' th
      		if cc[1] = '0' th
            continue;
        if Length(cc) > 7 th
        	continue;
        sc := StrToInt(cc);
        if Length(cc) = 7 th
          if sc > 1000000 th
            continue;
        M := Max(M, sa + sb + sc);
    en;
	en;
  Wln(M);
end.

program va;
var t:string;
    i,j,k:longint;
    t1,t2,t3,max,min:int64;
    s1,s2,s3:string;
function pd(a,b,c:string):boolean;
var t:longint;
begin
pd:=true;
if (a[1]='0') and (length(a)>1) then exit(false);
if (b[1]='0') and (length(b)>1) then exit(false);
if (c[1]='0') and (length(c)>1) then exit(false);
end;
procedure sp;
begin
 write('-1');
 halt;
end;
begin
 read(t);
 max:=-1;
 if length(t)>=21 then sp;
 for i:=1 to length(t) do
  for j:=i+1 to length(t) do
   for k:=j+1 to length(t) do
    begin
     s1:=copy(t,1,(j-1));
     s2:=copy(t,j,(k-j));
     s3:=copy(t,k,length(t));
     if pd(s1,s2,s3)=false then break;
     val(s1,t1); val(s2,t2); val(s3,t3);
     if t1>1000000 then break;
     if t2>1000000 then break;
     if t3>1000000 then break;
     if max<(t1+t2+t3) then max:=t1+t2+t3;
    end;
 write(max);
end.

var a1,a2,a3,p,n,m,j,i,k,l,max:longint;
x,y,z,s:string;
begin
{assign(input,'input.txt');reset(input);
assign(output,'output.txt');rewrite(output);  }
readln(S);
max:=-1;
for i:=1 to length(s) do
 for j:=i+1 to length(s) do
  begin
   x:=copy(s,1,i);
   y:=copy(s,i+1,j-i);
   z:=copy(s,j+1,length(s)-j);
   if (length(x)=0)or(length(y)=0)or(length(z)=0) then continue;
   if (length(x)>1)and(x[1]='0') then continue;
   if (length(y)>1)and(y[1]='0') then continue;
   if (length(z)>1)and(z[1]='0') then continue;
         val(x,a1,p);
         val(y,a2,p);
         val(z,a3,p);
         if a1>1000000 then continue;
         if a2>1000000 then continue;
         if a3>1000000 then continue;
         if (a1+a2+a3>max)then max:=a1+a2+a3;
  end;
writeln(max);
end.

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Const
   Source='input.txt';
   Target='output.txt';
Var
   s:String;
   n,f,i,k,r,max,j:Integer;
   w:String;
Begin
   Read(s);
   n:=length(s);
   f:=0;
   max:=0;
   For i:=1 To n-2 Do Begin
      If i>6 Then Break;
      For j:=i+1 To n-1 Do Begin
         r:=0;
         If (j-i)>5 Then Begin
             Continue;
         End;
         If (n-j)>5 Then Begin
             Continue;
         End;
         w:='';
         For k:=1 To i Do w:=w+s[k];
         //Write(w,' ');
         If (w[1]='0') and (length(w)>1) Then Continue;
         r:=r+strtoint(w);
         If strtoint(w)>1000000 Then Break;
         w:='';
         For k:=i+1 To j Do w:=w+s[k];
         //Write(w,' ');
         If (w[1]='0') and (length(w)>1) Then Continue;
         If strtoint(w)>1000000 Then Break;
         r:=r+strtoint(w);
         w:='';
         For k:=j+1 To n Do w:=w+s[k];
         //Write(w,' ');
         //WriteLn;
         If (w[1]='0') and (length(w)>1) Then Continue;
         f:=1;
         r:=r+strtoint(w);
         If strtoint(w)>1000000 Then Break;
         If r>max Then max:=r;
      End;
   End;
   If f=0 Then Begin
      Write(-1);
      Halt;
   End;
   Write(max);
End.

program A1;
var i,j,k,l,l1,l2,l3,ans:longint;
    s,s1,s2,s3:string;

Begin

 readln(s); l:=length(s);
 ans:=-1;
 for i:=1 to l-2 do
 begin
  s3:=s;
  for j:=1 to l-2 do
  begin
   s1:=copy(s3,1,i); delete(s3,1,i);
   s2:=copy(s3,1,j); delete(s3,1,j);
   val(s1,l1,k); val(s2,l2,k); val(s3,l3,k);
   if ((l1=0) and (s1<>'0')) or ((l1<>0) and (s1[1]='0')) or (l1>1000000) then continue;
   if ((l2=0) and (s2<>'0')) or ((l2<>0) and (s2[1]='0')) or (l2>1000000) then continue;
   if ((l3=0) and (s3<>'0')) or ((l3<>0) and (s3[1]='0')) or (l3>1000000) then continue;
   if (ans<l1+l2+l3) then
    ans:=l1+l2+l3;
  end;
 end;
 writeln(ans);

End.

program Prog;

{$APPTYPE CONSOLE}

{$R *.res}
uses sysutils;
var
st,a,s,d:string;
n,sum,max:longint;
i,j,k:integer;

begin
readln(st);
n:=length(st);
max:=-1;
if n>2 then
for i := 1 to n-2 do
  for j := i+1 to n-1 do
    begin

      a:=copy(st,1,i);
      s:=copy(st,i+1,j-i);
      d:=copy(st,j+1,n-j);
      if (length(a)<8)and(length(s)<8)and(length(d)<8) then
        if (length(inttostr(strtoint(a)))=length(a))and(length(inttostr(strtoint(s)))=length(s))and(length(inttostr(strtoint(d)))=length(d)) then begin
          sum:=strtoint(a)+strtoint(s)+strtoint(d);
          if (sum>max)and(sum<1000000) then max:=sum;
        end;
    end;
writeln(max);
readln;
end.

const nn=100;
var a:array[0..nn] of longint;   tt:integer;
    n,i,j,y,z,t,k,x:longint;s:string;
begin
 read(s);
 y:=-1;
 z:=length(s);
 for i:=1 to 7 do
 begin
  if ((i>1)and(s[1]<>'0'))or (i=1) then
 begin
  val(copy(s,1,i),x,tt);
  for j:=1 to 7 do
  if ((i+j)<z) and(z-i-j<8)then
  begin
   if ((j>1)and(s[i+1]<>'0'))or (j=1) then
   begin
   val(copy(s,1+i,j),k,tt);
   if ((z-i-j>1)and(s[i+j+1]<>'0'))or (z-i-j=1) then
   begin
   val(copy(s,1+i+j,z-i-j),t,tt);
   n:=x+k+t;
   if (n<1000001)and(n>y) then y:=n;
   end;
   end;
  end;
 end;
 end;
write(y);
end.

program ka;
var s,tmp1,tmp2,tmp3:string;
    i,j,ans,sum,l,k,a1,a2,a3,s1,s2,s3:longint;
    v:boolean;
Begin
  readln(s);
  l:=length(s);
   for i:=1 to l do
    if s[i]='0' then inc(k);
   v:=false;
   if k= l-k then v:=true ;
   if k=0 then v:=true;
   for i:=1 to l-1 do
    for j:=i+1 to l-1 do
      if i<>j then
      begin
         tmp1:=copy(s,1,i);
         tmp2:=copy(s,i+1,j-i);
         tmp3:=copy(s,j+1,l-j);
         s1:=length(tmp1);
         s2:=length(tmp2);
         s3:=length(tmp3);
         if v=false and(((tmp1[1]='0')and(tmp1[s1]<>'0')) or((tmp2[1]='0')and (tmp2[s2]<>'0')) or((tmp3[1]='0')and(tmp3[s3]<>'0'))) then
           begin
             writeln(-1);
             halt;
           end;
         val(tmp1,a1);
         val(tmp2,a2);
         val(tmp3,a3);
         sum:=a1+a2+a3;
         if sum>ans then ans:=sum;
      end;
      writeln(ans);
End.

program Project877;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  i,j,k,len:integer;
  s,a,b,c:ansistring;
  flag:boolean;
  sum,max:extended;
begin
  readln(s);
  len := length(s);
  max := -1;
  j :=2;
  while (j < len) and (j<8)  do
  begin
    k := j+1;
    while(k<len) and(k < j + 9) do
      begin
        a := copy(s,1,j-1);
        b := copy(s,j,k-j);
        c := copy(s,k, len - k+1);
        sum := 0;
        flag := true;
        if ((a[1] <> '0')or (length(a)=1)) and(strtofloat(a)<=1000000)  then
          sum := sum + strtofloat(a)
        else
          flag := false;
        if ((b[1] <> '0')or (length(b)=1))and(strtofloat(b)<=1000000)   then
          sum := sum + strtofloat(b)
        else
          flag := false;
        if ((c[1] <> '0')or (length(c)=1)) and(strtofloat(c)<=1000000)  then
         sum := sum + strtofloat(c)
        else
          flag := false;
        if(sum>max)and(flag) then max := sum;
        inc(k);
      end;
      inc(j);
  end;
      writeln(max:0:0);
      readln;
      readln;

end.